开发者

Arabic UTF Encoding to Percent Encoding in NSURL

开发者 https://www.devze.com 2023-03-30 23:10 出处:网络
am working on some mobile apps that send requests from mobile to internet via Http Requests the problem is that i send Arabic chars in this requests as parameters so i have to convert them from

am working on some mobile apps that send requests from mobile to internet via Http Requests

the problem is that i send Arabic chars in this requests as parameters so i have to convert them from

UTF-8 to Percent Encoding

i have a java based solution here :

http://mrxprt.com/blog/?p=454

[at the b开发者_如何学编程ottom of post u will find English Details : ]

but my problem now with Objective-C , how can it be done ?!


Try either

NSString *result =[sourceString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

or

NSString *result =(NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
                                                               (CFStringRef)sourceString,
                                                               NULL,
                                                               (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
                                                               CFStringConvertNSStringEncodingToEncoding(encoding));
0

精彩评论

暂无评论...
验证码 换一张
取 消