Problem when accessing a string using indexer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I load a text file into a string. Then I start seraching for a substring that appears many time in the file. Once I find an occurrence of the substirng I have to find the first accurance of " before it (there has to be one). Then I copy the substring starting with the first " until the index of the substring's occurrence
I find the occurrence of the substring without any problems, and in most cases, I find the first " without any problem either. But there are some places (always the same) where once I find the occurrence of the substring and try to find the first ", it finds something completely different. I know it will sound crazy, but for some reason the search for " jumps to another part of the file for no apparent reason
I've tried to debug and access each index and at a certain index it just jumps to another location in the file
I tried to find " using String.LastIndexOf, I tried manually and I tried using StringBuilder
I also tried to view the file of a hex editor to see if there are any strange characters in it that will cause it to jump to another location in the file, but found nothing..
I also checked, and the string I get as a result of the search doesn't appear anywhere in the file

Is it a bug or am I missing something here

Thanks!
 
Mike said:
I load a text file into a string. Then I start seraching for a
substring that appears many time in the file. Once I find an
occurrence of the substirng I have to find the first accurance of "
before it (there has to be one). Then I copy the substring starting
with the first " until the index of the substring's occurrence. I
find the occurrence of the substring without any problems, and in
most cases, I find the first " without any problem either. But there
are some places (always the same) where once I find the occurrence of
the substring and try to find the first ", it finds something
completely different. I know it will sound crazy, but for some reason
the search for " jumps to another part of the file for no apparent
reason! I've tried to debug and access each index and at a certain
index it just jumps to another location in the file. I tried to find
" using String.LastIndexOf, I tried manually and I tried using
StringBuilder. I also tried to view the file of a hex editor to see
if there are any strange characters in it that will cause it to jump
to another location in the file, but found nothing... I also checked,
and the string I get as a result of the search doesn't appear
anywhere in the file!

Is it a bug or am I missing something here?

Sounds like it could well be an encoding problem, to be honest. What
encoding is the file in, and how are you reading it? If you dump the
string into a textbox, does everything look okay?

If that doesn't help, please try to come up with a short but complete
example which demonstrates the problem.
 
I found the problem. I was reading the file using a stream, and I read it into a buffer incorrectly, so I must have had illegal characters in the string while I was trying to read it

Thanks for the help!
 

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

Back
Top