Search()
{
CString str(_T("he个字符串中含有lp"));int i = str.GetLength();
for(int j=0; j<i; j++)
{
    TCHAR h = str.GetAt(j);
    if(  (h<0XA0B0 && h>122) || h>0xfef7 || (h>90 && h<97) ||(h>57 && h<65) || h<48 }
       return FALSE;
}
    return TRUE;
}
这个连标点也也排除了,前面要定义_UNICODE

解决方案 »

  1.   

    怎么定义前面要定义_UNICODE呀。我不会用呀!!1
      

  2.   

    _UNICODE加入工程设置中

    #define _UNICODE--------------------
    也有其它办法,如下Search(TCHAR* ch) // 这个是你传进来的,要检测的字符串
    {
    WCHAR* pw = A2W(ch);int i = strlen(ch);
    for(int j=0; j<i; j++)
    {
        WCHAR h = pw[j];
        if(  (h<0XA0B0 && h>122) || h>0xfef7 || (h>90 && h<97) ||(h>57 && h<65) || h<48 }
           return FALSE;
    }
        return TRUE;
    }
      

  3.   

    新人问2个问题
    1,#define   _UNICODE 写在那里!!!
    2,我用的是cstring。你改一下程序好不。
    顺便问一句。你的能编译出来么!!!
      

  4.   

    1,#define       _UNICODE   一般写在stdafx.h中,因为所有文件都包含它。
    CString是可以转换为TCHAR指针的。
    shunruo给你写的函数已经很明了了,汉字为双字节,是利用字符的ASCII码进行比较,应该没有问题,我没有测试过。
    我帮你试试改写下,你自己再试试,版权属于shunruo。
    BOOL Search(str)
    {
        //CString str(_T("he个字符串中含有lp"));
        TCHAR h;
        int i = str.GetLength();
        int j =0;
        for(j=0; j<i; j++)
        {
          //TCHAR h = str.GetAt(j);
          h= str.GetAt(j);
          if(  (h<0XA0B0 && h>0x122) || h>0xfef7 || (h>0x90 && h<0x97) ||(h>0x57 && h<0x65) || h<0x48 }
             return FALSE;
        }
        return TRUE;
    }
    祝你好运!
      

  5.   

    大哥门。搞不定呀,#define               _UNICODE       能不能不用这个呀。用了这个更家的乱了。有没有不用这个搞顶的
      

  6.   

    为什么会乱?要处理中文字符,就得用UNICODE,不定义的话你试试下面的方法。
    环境VS 2005:
    在项目文件上右击选择属性,在属性中配置属性->常规,在右侧选字符集,选择使用 Unicode 字符集,你试试看。
      

  7.   

    楼上的写的是对的~
    好像也不用定义_UNICODE     只是上面的代码有一点格式错误,这个应该可以,我试了的:
    BOOL Search(CString str) // 这个是你传进来的,要检测的字符串
    { for(int i=0; i<str.GetLength(); i++)
    {
    WCHAR h = str.GetAt(i); 
    if(  (h<0XA0B0 && h>122) || h>0xfef7 || (h>90 && h<97) ||(h>57 && h<65) || h<48) 
    return FALSE;
    }
    return TRUE;
    }          
      

  8.   

    格式上不存在问题,我用的是VS 2005,你用的是VC6吧?是比较h的逻辑表达式写的有问题。
    for循环中i变量最好在外面定义,还有h,用TCHAR比WCHAR通用,虽然在UNICODE下相同,定义在for循环外好一点。
    你的写法会降低执行速度的,如果该函数会被多次执行时就会增大影响了。
    for循环中每次比较i的值都需要进行一次str.GetLength()操作。
      

  9.   

    IsDBCSLeadByteEx()是否汉字
    isdigit()是否数字
    isalpha()是否字母
      

  10.   

    http://topic.csdn.net/u/20071031/20/23955adb-887a-4bc1-9a97-a5121b859754.html
      

  11.   

    bobob大侠说的很对,我查了一下MSDN,的确学习了下。
    还查到一个博客:http://mailao.yculblog.com/post.1637713.html
    int nLength=m_Text.GetLength();
    int i=0;
    while(i<nLength)
    {
    char ch=m_Text.GetAt(i);
    if( (IsDBCSLeadByteEx(936,ch)) || (IsDBCSLeadByteEx(950,ch)) )
    {
    i+=2; //简体 or 繁体
    }
    else
    {
    i+=1;
    }
    }它这个函数利用的代码页,应该更准确。
    还能判断是简体中文还是繁体中文,有增长了知识,下回应该都看看MSDN了。呵呵,谢谢bobob大侠。
      

  12.   

    IsDBCSLeadByteEx()是否汉字 
    isdigit()是否数字 
    isalpha()是否字母Remember it.
      

  13.   

    core java的应用
    public class StringFil { public String stringTest() {
    String str = "hahahah1234=="; for (int j = 0; j < str.length(); j++) {
    char h = str.charAt(j);
    if ((h < 0XA0B0 && h > 122) || h > 0xfef7 || (h > 90 && h < 97)
    || (h > 57 && h < 65) || h < 48) {
    return "false";
    } }
    return "true";
    } public static void main(String[] args) {
    System.out.println(new StringFil().stringTest());
    }}
      

  14.   

    用正则表达式~~简单明了~~~~
    /// <summary>
    /// 判断是否为中文,或者英文,或者数字组成的字符串
    /// True:是
    /// False:不是
    /// </summary>
    public static bool OnCheckSpecialChar(string p_cStr)
    {
    string strPat = @"^[a-zA-Z0-9\u4e00-\u9fa5]+$";
    Regex objRg = new Regex(strPat);
    bool bFlag = objRg.IsMatch(p_cStr);
    return bFlag;
    }
      

  15.   

    转成unicode,感觉效率会高些。