Skip to content

Instantly share code, notes, and snippets.

@xuyunan
Created May 31, 2013 05:27
Show Gist options
  • Save xuyunan/5683076 to your computer and use it in GitHub Desktop.
Save xuyunan/5683076 to your computer and use it in GitHub Desktop.
统计字数
+ (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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment