将字符串中的中文重新组合:
public string IsChina(string CString)
{
string str1="";
for (int i=0; i{
if (Convert.ToInt32(Convert.ToChar(CString.Substring(i, 1))) > Convert.ToInt32(Convert.ToChar(128)))
{
str1 = str1 + CString.Substring(i, 2);
i++;
continue;
}
}
return str1;
}
下班之前帮你搞定下,如果存在中文就把中文返回出来,下面是代码
private void Form1_Load(object sender, EventArgs e)
{
string path = Application.StartupPath+"\\test.txt";
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
StreamReader m_streamReader = new StreamReader(path, System.Text.Encoding.GetEncoding("GB2312"));
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
string strLine = m_streamReader.ReadLine();
string code = "";
while (strLine != null)
{
code += strLine + "\n";
strLine = m_streamReader.ReadLine();
}
m_streamReader.Close();
string charN = IsChinaStr(code);
}
public string IsChinaStr(string CString)
{
string rt = "";
for (int i = 0; i < CString.Length; i++)
{
if (Convert.ToInt32(Convert.ToChar(CString.Substring(i, 1))) > Convert.ToInt32(Convert.ToChar(128)))
{
rt += CString.Substring(i, 1).ToString();
}
}
return rt;
}
在它的那个基础上还要添加字符的判断,可以查看字符的ASCII编码,或者用char.IsUpper()和char.IsLower()这两个方法(貌似是这个两个方法,有点不记得了,会自动提示的)。
用正则表达式