- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"--first-%i",[self convertToInt:@"123我爱你"]);
NSLog(@"--second--%ld",[self getToInt:@"123我爱你"]);
}
- (int)convertToInt:(NSString*)strtemp
{
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
if (*p) {
p++;
strlength++;
}
else {
p++;
}
}
return strlength;
}
- (NSInteger)getToInt:(NSString*)strtemp
{
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
NSData* da = [strtemp dataUsingEncoding:enc];
return [da length];
}