截取到指定个数字符串、获取汉字个数

#pragma mark - 截取到指定个数字符串
- (NSString *)subStringOfContent:(NSString *)content {
    NSInteger count = 0;
    NSInteger recordCount = 0;
    NSString *subString = nil;
    for (int i = 0; i=0x4E00 && c <=0x9FA5) {
            
            count++ ;//汉字
            if (count == 150) {
                recordCount = i;
            }
        }
    }
    subString = [content substringToIndex:recordCount];
    return [NSString stringWithFormat:@"%@...",subString];
}

#pragma mark - 获取汉字个数
+ (NSInteger)chineseCountOfString:(NSString *)string {
    
    NSInteger ChineseCount = 0;
    
    if (string.length == 0) return 0;

    
    for (int i = 0; i=0x4E00 && c <=0x9FA5)        {
            
            ChineseCount++ ;//汉字
            
        }
    }
    return ChineseCount;
    
}

你可能感兴趣的:(截取到指定个数字符串、获取汉字个数)