Created
April 9, 2011 17:52
-
-
Save lvyile/911606 to your computer and use it in GitHub Desktop.
新浪微博对每条信息有 140 字的上限限制,所以 CocoaChia 会员“keefo”分享了他的新浪微博字数统计函数,做微博客户端应用的开发者可以以此加入字数统计功能以方便用户
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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