您的位置:首页 > 其它

检测字符串中是否有中文

2004-09-25 12:34 295 查看
[DllImport("KERNEL32.DLL", SetLastError=true,
CharSet=CharSet.Unicode, ExactSpelling=true,
CallingConvention=CallingConvention.StdCall)]
private static extern int WideCharToMultiByte(
uint CodePage,
uint dwFlags,
string lpWideCharStr,
int cchWideChar,
string lpMultiByteStr,
int cchMultiByte,
string lpDefaultChar,
int lpUsedDefaultChar);

private const uint CP_ACP=0x0;

public void IsHaveChinese()
{
string m_str="中ABC言语";
int nLen=WideCharToMultiByte(CP_ACP,0,m_str,m_str.Length,null,0,null,0);
if (m_str.Length != nLen)
{
MessageBox.Show("有中文字符。");
}
else
{
MessageBox.Show("没有中文字符。");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: