判断中、英文、数字、符号

swift 判断String里面包含的中、英文、数字、符号。并附汉字Unicode字符编码表。 Unicode字符编码表–下载

let text = “文字内容text123😄” for commitChar in text.unicodeScalars { //字符串只有一个字符,这个循环只会执行1次 print(Int(commitChar.value))

    if ((commitChar.value>=0x4e00)&&(commitChar.value<=0x9FA5)) {
        //字符为中文
        print("字符为中文")
    } else if((commitChar.value>64)&&(commitChar.value<91)){
        print("字符为大写英文字母")
    }else if((commitChar.value>96)&&(commitChar.value<123)){
        print("字符为小写英文字母")
    }else if((commitChar.value>47)&&(commitChar.value<58)){
        print("字符为数字")
    }else{
        print("其他字符")
    }

}
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy