//微博对每条信息有 140 字的上限限制,下面微博字数统计函数,做微博客户端应用的开发者可以以此加入字数统计功能以方便用户 |
- ( int )countWord:(NSString*)s |
{ |
int i,n=[s length],l=0,a=0,b=0; |
unichar c; |
for (i=0;i<n;i++){ |
c=[s characterAtIndex:i]; |
if (isblank(c)){ |
b++; |
} else if (isascii(c)){ |
a++; |
} else { |
l++; |
} |
} |
if (a==0 && l==0) return 0; |
return l+( int )ceilf(( float )(a+b)/2.0); |
} |
by: 发表于:2017-10-25 10:45:12 顶(0) | 踩(0) 回复
??
回复评论