zoukankan      html  css  js  c++  java
  • [转载]NSString中判断中文,英文,数字

    曾有需求做个用户名中非法字符的判断,要求是只能输入中英文和数字,其他字符一律非法,故写了下边一个程序mark一下吧~~

    NSString *testString = @"春1mianBU觉晓";

    NSString *perchar;

        int alength = [testString length];

        for (int i = 0; i<alength; i++) {

            char commitChar = [testString characterAtIndex:i];

            NSString *temp = [testString substringWithRange:NSMakeRange(i,1)];

            const char *u8Temp = [temp UTF8String];

            if (3==strlen(u8Temp)){

                NSLog(@"字符串中含有中文");

            }else if((commitChar>64)&&(commitChar<91)){

        NSLog(@"字符串中含有大写英文字母");

            }else if((commitChar>96)&&(commitChar<123)){

                NSLog(@"字符串中含有小写英文字母");

            }else if((commitChar>47)&&(commitChar<58)){

                NSLog(@"字符串中含有数字");

            }else{

        NSLog(@"字符串中含有非法字符");

    }

        }

  • 相关阅读:
    bzoj2733: [HNOI2012]永无乡
    bzoj3141: [Hnoi2013]旅行
    bzoj3144: [Hnoi2013]切糕
    bzoj3140: [Hnoi2013]消毒
    bzoj3139: [Hnoi2013]比赛
    bzoj3142: [Hnoi2013]数列
    bzoj3572: [Hnoi2014]世界树
    bzoj2286: [Sdoi2011]消耗战
    bzoj3611: [Heoi2014]大工程
    The Unsolvable Problem
  • 原文地址:https://www.cnblogs.com/mafeng/p/5245037.html
Copyright © 2011-2022 走看看