c#字符串的搜索,及中文字符

来源:百度知道 编辑:UC知道 时间:2024/05/31 23:07:07
用indexof没有办法搜索中文字符吗?
在c#中怎样才能搜索一串中文字符?

public static string CutString(string inputString,int len)
{

ASCIIEncoding ascii = new ASCIIEncoding();
int tempLen=0;
string tempString="";
byte[] s = ascii.GetBytes(inputString);
for(int i=0;i<s.Length;i++)
{
if((int)s[i]==63)
{
tempLen+=2;
}
else
{
tempLen+=1;
}
try
{
tempString+=inputString.Substring(i,1);
}
catch
{
break;
}
if(tempLen>len)
break;
}

有吧,C#代码采用Unicode字符集,包含所有的字符。

在属性里设置,加入简体中文

indexof