Joe*_*oey 11
如下?
string1 = "hi i'm tibinmathew @ i'm fine";
string2 = "tibin";
if (string1.Contains(string2))
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
对于简单的子串,这是有效的.还有像StartsWith和的方法EndsWith.
对于更精细的匹配,您可能需要正则表达式:
Regex re = new Regex(@"hi.*I'm fine", RegexOptions.IgnoreCase);
if (re.Match(string1))
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
看起来你只是想看看第一个字符串是否有一个匹配第二个字符串的子字符串,在它里面的任何地方.你可以这样做:
if (string1.Contains(string2))
{
// Do stuff
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
319 次 |
| 最近记录: |