NSURL URLWithString:对于非英语重音字符为空 [英] NSURL URLWithString: is null with non-english accented characters

查看:176
本文介绍了NSURL URLWithString:对于非英语重音字符为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串...

I have the following string...

NSString *googleSearchString = @"http://www.google.com/search?q=lyrics+%22Tænder+På+Dig%22+%22Jakob+Sveistrup%22";

请注意,它有一些重音字符。当我试图把它变成一个url返回的url是null ...

Notice that it has some accented characters. When I try to turn that into a url the returned url is null...

[NSURL URLWithString:googleSearchString];

因此,通常url工作除非字符串中有非重音符号。

So normally the url works except when there are accented non-english characters in the string. Any help on how to handle that?

推荐答案

您需要转义特殊字符才能使其正常工作。类似:

You need to escape the special characters to make it work properly. Something like:

[NSURL URLWithString:[googlSearchString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

这篇关于NSURL URLWithString:对于非英语重音字符为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆