String#LastIndexOf

  • Thread starter Thread starter Mathias Weyel
  • Start date Start date
M

Mathias Weyel

Hi Group!

I encounter a strange behaviour of String.LastIndexOf when specifying
start and count values.

The following works:

string tempString = orgString.SubString(0, mycount);
int index = tempString.LastIndexOf(mychar);

The following causes an ArgumentOutOfRangeException:

int index = orgString.LastIndexOf(mychar, 0, mycount);

Values at the time of execution:

mychar: '<'
orgString.Length: 6347
mycount: 663

Is this a known issue (Framework version 2.0)?

cheers

Mathias
 
The following causes an ArgumentOutOfRangeException:

int index = orgString.LastIndexOf(mychar, 0, mycount);

Values at the time of execution:

mychar: '<'
orgString.Length: 6347
mycount: 663

Is this a known issue (Framework version 2.0)?

No, it's a bug in your code and the documentation. You're asking it to
look backwards from the first character (0) for 663 characters.

Basically there's an undocumented but logical constraint that count <=
startIndex+1.

If I remember, I'll add a note to connect.microsoft.com - or you can,
of course.

Now, where did you actually *want* to start searching from? I assume
you didn't really mean to only look at the first character.

Jon
 
Well, exactly as the "working" code was doing. I have a string and am
looking for some char within the substring from 0 to index. According to
your words, replacing the 0 with mycount should do (and even actually
does) the trick.

Thanks for your help!

No problem. Let me know whether or not you log file documentation bug,
so that I can do it if you don't...

Jon
 
Jon said:
No, it's a bug in your code and the documentation. You're asking it to
look backwards from the first character (0) for 663 characters.

Basically there's an undocumented but logical constraint that count <=
startIndex+1.

If I remember, I'll add a note to connect.microsoft.com - or you can,
of course.

Now, where did you actually *want* to start searching from? I assume
you didn't really mean to only look at the first character.

Jon

Well, exactly as the "working" code was doing. I have a string and am
looking for some char within the substring from 0 to index. According to
your words, replacing the 0 with mycount should do (and even actually
does) the trick.

Thanks for your help!

Mathias
 
Jon said:
No problem. Let me know whether or not you log file documentation bug,
so that I can do it if you don't...

Jon

I'd be glad if you could, I have never done so before and currently have
no time digging through the pages to file an appropriate report.

Thx!

Mathias
 
I'd be glad if you could, I have never done so before and currently have
no time digging through the pages to file an appropriate report.

Well, I'm not exactly flush with time myself - but I'll file it :)

Jon
 
Jon said:
Well, I'm not exactly flush with time myself - but I'll file it :)

Jon

Well, at least you know how to do properly in the sense of where to put
what information how.
I've had enough badly formed error reports to be somewhat careful about
these things.

I'll tell you as soon as I have had a chance to look into it myself,
then I can file one for you in return. :)

Mathias
 

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