Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios UTF8 encoding from nsstring

I am receiving a nsstring that is not properly encoded like "mystring%201, where must be "mystring 1". How could I replace all characters that could be interpreted as UTF8? I read a lot of posts but not a full solution. Please note that nsstring is already encoded wrong and I am not asking about how to encode char sequence. Thank you.

like image 451
Jaume Avatar asked Aug 02 '12 21:08

Jaume


Video Answer


2 Answers

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding is what you want. basically use it like so:

newString = [myString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
like image 51
Jesse Naugher Avatar answered Oct 07 '22 00:10

Jesse Naugher


[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
like image 35
Osama Khalifa Avatar answered Oct 07 '22 01:10

Osama Khalifa