IndexOf and LastIndexOf not working

N

.Net Sports

Using StreamReader to open and read files, I'm trying to parse some
text within a file at a starting point grabbing all the text to the
ending point; it works on one particular file (a .txt file)
with no problem, but on an .asp file when I try it

abc1 = xyz1.Substring(xyz1.IndexOf("starting keyword"),
xyz1.LastIndexOf("ending keyword"))
Response.Write(abc1)

it goes beyond the LastIndexOf keyword and grabs a bunch of following
text (about the next 4r or 5 lines)... my ending keyword only shows up
once in the particular file I'm trying to parse, so I know I'm not
doing anything wrong there.
????
NetSports
 
M

Mark Milley

I'd start by doing something like this to see if you're getting what
you're exepcting from the search functions:

response.write(string.format("Starting Keyword
Postion:{0}<br>",xyz1.IndexOf("starting keyword")))

response.write(string.format("Ending Keyword
Postion:{0}<br>",xyz1.LastIndexOf("Ending keyword")))

Then see what it's finding at the ending keyword position.
 
N

.Net Sports

Thanks for the insight , and how to use the Position method here, but I
need to find out with the code I posted why I'm getting text beyond my
Ending Keyword here when I need it to stop at the Ending Keyword

..netsports
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top