简体   繁体   中英

Workaround for String.Contains() in C# .NetCF 2.0?

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

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

那么string.IndexOf ,只是检查它是否返回大于-1?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM