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

来源:互联网 发布:支票打印软件破解版 编辑:程序博客网 时间:2024/05/14 15:44

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


-(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;

    

}

1 0