string function that finds substring within string

  • Thread starter Thread starter vaughn
  • Start date Start date
V

vaughn

Is there some function that will return a boolean if a certain substring is
inside another string(eg. Is "name" inside 'My name is")? And if it finds
the substring, will it tell me in what position?

Thanks.
 
hi vaughn,

string MyString = "My name is";
int pos = MyString.IndexOf("name");

if "name" not found, pos will be -1 else the actual index.

regards,
 
vaughn said:
Is there some function that will return a boolean if a certain substring is
inside another string(eg. Is "name" inside 'My name is")? And if it finds
the substring, will it tell me in what position?

Thanks.

string test = "abcDEF";

if (test.LastIndexOf("DEF") > -1)
{
....
}
 
Back
Top