iphone:URL initWithString 返回为空
Parameters
URLString
-
The string with which to initialize the NSURL object. This string must conform to URL format as described in RFC 2396. This method parses URLString according to RFCs 1738 and 1808.
Discussion
This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
所以URLString中有空格的要变成:%20
[urlstring stringByReplacingOccurrencesOfString:@" "withString:@"%20"]]
然后还要进行编码转换
str=[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
作者:老Zhan
出处:http://www.cnblogs.com/mybkn/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。