ios 怎么计算规定大小的字符串长度
1个回答
展开全部
- (int)textLength:(NSString *)text//计算字符串长度
{
float number = 0.0;
for (int index = 0; index < [text length]; index++)
{
NSString *character = [text substringWithRange:NSMakeRange(index, 1)];
if ([character lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 3)
{
number++;
}
else
{
number = number + 0.5;
}
}
return ceil(number);
}
{
float number = 0.0;
for (int index = 0; index < [text length]; index++)
{
NSString *character = [text substringWithRange:NSMakeRange(index, 1)];
if ([character lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 3)
{
number++;
}
else
{
number = number + 0.5;
}
}
return ceil(number);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询