Created
September 16, 2015 03:18
-
-
Save dabing1022/cb2903394378f1720c11 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
// @"一中华abc" 8 | |
- (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; | |
} | |
// @"一中华abc" 9 | |
- (int)getToInt:(NSString*)strtemp | |
{ | |
NSStringEncoding enc = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); | |
NSData* da = [strtemp dataUsingEncoding:enc]; | |
return[da length]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment