0=String IndexOf same as empty string.

G

Guest

I'm using IndexOf on my strings to find if there are certain words contained
in a string. Well, this works fine except when I'm looking at an empty
string, because the return value is zero based index. With an empty string it
also returns 0, the same as it would with a string where it starts in the
first position (zero value). Is there anyting else to use to search for a
string in the .Net framework or is there a was to use IndexOf with empty
strings but give back something you can count on.
 
G

Guest

Chris,
I suppose you could design something using the ternary operator
(untested sample code):

int myInfo =myString.Length>0?myString.IndexOf(mytest):-1;
In VB.NET you would do the same thing with IIf
Peter
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top