views:

265

answers:

3

There is a string method called Contains. It allows you to quickly search a string for another string. I need to use this in a .netcf 2.0 application but per MSDN it does not come available until the 3.5 framework.

Can anyone offer a work around (C#)?

TIA Noble

+8  A: 

Hi, You could try using String.IndexOf. If it returns -1, the string does not exist inside the other string.

keyboardP
+2  A: 

What about string.IndexOf and just check to see if it returns greater than -1?

Matt Greer
+1  A: 

Browsing "String.Contains" in Reflector gives below. I think this can be used directly in code.

Public Function Contains(ByVal value As String) As Boolean
    Return (Me.IndexOf(value, StringComparison.Ordinal) >= 0)
End Function

Also a C# version

public bool Contains(string value)
{
    return (this.IndexOf(value, StringComparison.Ordinal) >= 0);
}
geekonweb