美文网首页
两个英文字符占一个长度。

两个英文字符占一个长度。

作者: 冲上云霄90 | 来源:发表于2016-06-02 14:36 被阅读9次

- (int)countTheStrLength:(NSString*)strtemp {

int strlength =0;

char* p = (char*)[strtempcStringUsingEncoding:NSUnicodeStringEncoding];

for(inti=0; i<[strtemplengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {

if(*p) {

p++;

strlength++;

}

else{

p++;

}

}

return(strlength+1)/2;

}

相关文章

网友评论

      本文标题:两个英文字符占一个长度。

      本文链接:https://www.haomeiwen.com/subject/zllkdttx.html