计算NSString的字符长度(和length有区别)
1 - (int)calc_charsetNum:(NSString*)_str 2 { 3 unsigned result = 0; 4 const char *tchar=[_str UTF8String]; 5 if (NULL == tchar) { 6 return result; 7 } 8 9 10 for (int i=0; i<strlen(tchar);) 11 { 12 unsigned t = tchar; 13 if( t >= 224 ) 14 i = i+3; 15 else if( t >= 192 ) 16 i = i+2; 17 else 18 i++; 19 result++; 20 } 21 22 return result; 23 24 }
先留下来备用