Created
May 31, 2013 05:27
-
-
Save xuyunan/5683076 to your computer and use it in GitHub Desktop.
统计字数
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)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