转义特殊字符(ø,æ)以便在网址内使用 [英] Escaping special characters (ø, æ) for use inside a url
本文介绍了转义特殊字符(ø,æ)以便在网址内使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在iOS应用程序中显示带有URL源的图像,但它没有显示。
I try to display an image with a URL source in an iOS application, but it doesn't show up.
图像的url是实例示例路径。
The url of the image is live example path.
使用以下Objective-C代码转义此字符串时:
When escaping this string using the following Objective-C code:
NSString *url= [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)originalpath, NULL, CFSTR("øæ"), kCFStringEncodingUTF8) autorelease];
结果是(编码为øæ):live xml path
the result is (with encoding of øæ) : live xml path
我存储URL的所有文件都使用文本编码(UTF-8)。
All my files where the URLs are stored use text encoding (UTF-8).
如何以正确的方式转义URL,如此图像将被显示?
How do I escape the URL in a right way, such that the image will be displayed?
推荐答案
不要去ascii编码试试吧
don't go for ascii encoding try it
NSString *URLString = [yourImagepath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:URLString];
我希望它会帮助你。
这篇关于转义特殊字符(ø,æ)以便在网址内使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文