入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

iOS判断一段字符串长度(汉字2字节)

创建时间:2017-05-27 投稿人: 浏览次数:646
-(NSUInteger)textLength: (NSString *) text{

    NSUInteger asciiLength = 0;

    for (NSUInteger i = 0; i < text.length; i++) {


        unichar uc = [text characterAtIndex: i];

        asciiLength += isascii(uc) ? 1 : 2;
    }

    NSUInteger unicodeLength = asciiLength;

    return unicodeLength;

}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像