473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem when accessing a string using indexer

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!
Nov 16 '05 #1
2 1545
Mike <an*******@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
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!
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Daniel Billingsley | last post by:
I've got to believe this is a fairly common / classic problem, and I think I've even read an example somewhere in my education thus far, but I sure can't remember it. Suppose I want to store a...
1
by: mdub317 | last post by:
I'm totally new to programming and I am wondering; when would be a good time to use an array or an indexer? I want to know what types of applications would make good use of arrays or indexers. ...
3
by: JJ | last post by:
Hi, I have created an Arraylist object from an Arraylist class. I added rows to the arraylist object and I need to find a particular record in my arraylist. How do I do this? Also if I was in...
5
by: gmccallum | last post by:
I am trying to convert the value of a string to a defined enum value such as follows. public enum MyEnum { One, Two }; string MyString = "One"; // or even this is fine string MyString2 =...
5
by: SpotNet | last post by:
Hello NewsGroup, I have a custom class and a collection for that custom class that inherits CollectionBase. As such; public class MyClass { private string datamember1 = string.Empty,...
2
by: Robert W. | last post by:
In a posting earlier this year I found a simple approach to convert a string to a particular Enum value. The one line solution looked like this: MyEnum ConvertedString = (MyEnum)...
5
by: Clive Dixon | last post by:
Is it possible to access an indexer of a base class with identical signature, e.g. class Class1 { public object this { get { // ...
2
by: Ryan Liu | last post by:
Is DataRow uses DataRow and DataRow much efficient than DataRow? Thanks, ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. Ryan Liu Shanghai Fengpu Software Co. Ltd Shanghai , China
6
by: abir | last post by:
i have a template as shown template<typename Sclass Indexer{}; i want to have a specialization for std::vector both const & non const version. template<typename T,typename Aclass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.