check if string contain substring

  • Thread starter Thread starter Ivan Demkovitch
  • Start date Start date
I

Ivan Demkovitch

Hi!

I would like to check if string contain specific substring.

How to do it?

P.S. I've done something stupid like

String.Replace

If str1<>str2....
 
Ivan,

In the .net help index, lookup the string class, and then look at all the
methods available. For instance, the IndexOf method might do the trick.

String strMyString = "Neat";
Int32 iLocation = strMyString.IndexOf("a");

if ( iLocation >= 0 )
{
//Do something
}

Mark
 
I would do something like this:

if (str.IndexOf(str2) == -1) ...

IndexOf returns -1 it cannot find str2 in str1

Dave
 
Thank you guys!

Thats indeed nicer way of doing it.

I looked thru sring class like 5 times and didn't stop on IndexOf() :-)
 
Back
Top