.NET中字符包含问题

来源:百度知道 编辑:UC知道 时间:2024/09/28 14:14:30
如何判断一个中文字符串中是否包含某个字符串,例如: 判断字符串:
"河北省-台湾省-石家庄市-台北市"是否包含:"石家庄市"
请各位高手指教!

String.Contains方法,例:

string s1 = "河北省-台湾省-石家庄市-台北市";
string s2 = "石家庄市";
bool b = s1.Contains(s2);
Console.WriteLine("Is the string, s2, in the string, s1?: {0}", b);

String str="河北省-台湾省-石家庄市-台北市";
String st="石家庄市";
Boolean b=false;
String [] newstr=str.Split('-');
int n=newstr.Length;
for(int i=0;i<n;i++)
{
if(newstr[i].Equals(st))
{
b=true;
break;
}
}
if(b==true)
{
Response.Write("<script language='javascript'>alert('包含')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('不包含')</script>");
}

c++的是
CString str="河北省-台湾省-石家庄市-台北市"
BOOL bbh=str.Find("石家庄市");

indexof()函数