检测字符串中是否有中文

[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("没有中文字符。");
    }
}

posted @ 2004-09-25 12:34  greystar  阅读(682)  评论(0编辑  收藏  举报