Skip to content

Instantly share code, notes, and snippets.

@lvyile
Created April 9, 2011 17:52
Show Gist options
  • Save lvyile/911606 to your computer and use it in GitHub Desktop.
Save lvyile/911606 to your computer and use it in GitHub Desktop.
新浪微博对每条信息有 140 字的上限限制,所以 CocoaChia 会员“keefo”分享了他的新浪微博字数统计函数,做微博客户端应用的开发者可以以此加入字数统计功能以方便用户
- (int)sinaCountWord:(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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment