
c#怎么判断字符串中是否包含某两个字符串
2个回答
展开全部
使用字符串的IndexOf方法查找,找到返回正确的位置下标,未找到返回-1
举例:
string str = "我爱北京天安门";
int index = str.IndexOf("爱");
if (index > -1)
{
Console.Write("找到了");
}
else {
Console.Write("未找到");
}
Console.Read();
举例:
string str = "我爱北京天安门";
int index = str.IndexOf("爱");
if (index > -1)
{
Console.Write("找到了");
}
else {
Console.Write("未找到");
}
Console.Read();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询