分享到新浪时字数超过140后跳转不出去,这里需要计算content的大小
swift 方法
private func sinaCountWord(str:NSString) -> Int {
let n:Int = str.length
var l:Int = 0
var a:Int = 0
var b:Int = 0
var c:unichar
for i in 0...n-1 {
c = str.characterAtIndex(i)
if isblank(Int32(c)) == Int32(1) {
b += 1
}else if isascii(Int32(c)) == Int32(1) {
a += 1
}else {
l += 1
}
}
if a == 0 && l == 0 {
return 0
}
return l + Int(ceilf((Float(a+b))/2.0))
}
OC方法
- (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);
}