My Question is regarding special Character in NSString.
Actual name:- Yusuf Doğan
Retrieve name= Yusuf Do\u011fan
My Actual fb friend name is Yusuf Doğan (Check Special "g with ~ cap").
I take it as NSdata and then converter it in to nsstring.
NSString *stringResponse = [[NSString alloc] initWithData:response encoding:NSUTF8StringEnco开发者_如何学JAVAding];
But the nsstring shows it as
"Yusuf Do\u011fan"
Similar cause with the following.
Ricsi Zoványi as Ricsi Zov\u00e1nyi
Pero Perić as Pero Peri\u0107
Any Solution.
Thanks in advance.
You can try this:
NSString *source = [NSString stringWithString:_username];
[_username release];
NSMutableString *result = [[NSMutableString alloc] init];
NSScanner *scanner = [NSScanner scannerWithString:source];
[scanner setCharactersToBeSkipped:nil];
while (![scanner isAtEnd]) {
NSString *chunk;
// Scan up to the Unicode marker
[scanner scanUpToString:@"\\u" intoString:&chunk];
// Append the chunk read
[result appendString:chunk];
// Skip the Unicode marker
if ([scanner scanString:@"\\u" intoString:nil]) {
// Read the Unicode value (assume they are hexa and four)
unsigned int value;
NSRange range = NSMakeRange([scanner scanLocation], 4);
NSString *code = [source substringWithRange:range];
[[NSScanner scannerWithString:code] scanHexInt:&value];
unichar c = (unichar) value;
// Append the character
[result appendFormat:@"%C", c];
// Move the scanner past the Unicode value
[scanner scanString:code intoString:nil];
}
}
_username = [[NSString stringWithFormat:@"%@",result] retain];
[result release];
}
Instead of "NSUTF8StringEncoding" use "NSUTF16StringEncoding". I think this may solve your issue.
精彩评论