Reputation: 901
I am receiving a string from the internet but i cant find a way to transform the special char and them show in on an alert box. This is the string:
@"Sorry, your search doesn\u0027t have any result"
i know i could do something like this to work around
[response stringByReplacingOccurrencesOfString:@"\u0027" withString:@"'"];
but i wanted a solution that would work for any character
i have already tried several solution but none seam to work, and i don't know why
Upvotes: 2
Views: 203
Reputation: 138
Try
NSString* string = [NSString stringWithUTF8String:[response cStringUsingEncoding:NSUTF8StringEncoding]];
This should work.
Upvotes: 0
Reputation: 21147
You can do it like this:
NSString *escapedStr = @"Sorry, your search doesn\\u0027t have any result";
NSString *unescapedStr = [NSString
stringWithCString:[escapedStr cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding];
NSLog(@"unescapedStr = %@", unescapedStr);
Upvotes: 3