我有一个弦
https://www.example.com/abc/Gesture-abc-mobile-app_%257E0177cae9d41f573e5f?source=rss
当我使用此方法在Url中对其进行转换以加载
UIWebView
NSString *str = [[NSString stringWithFormat:@"%@", self.urlStr] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
输出为:
https://www.example.com/jobs/Gesture-initiated-mobile-app_%257E0177cae9d41f573e5f?source=rss%0A%20%20%20%20%20%20
告诉我为什么会这样...
最佳答案
字符串末尾还有多余的字符-回车符和准确的空格:
NSString *urlStr = @"https://www.example.com/abc/Gesture-abc-mobile-app_%257E0177cae9d41f573e5f?source=rss\n ";
结果:
https://www.example.com/abc/Gesture-abc-mobile-app_%25257E0177cae9d41f573e5f?source=rss%0A%20%20%20%20%20
最后删除垃圾,您将获得所需的结果。
关于ios - 通过此方法更改NSURL字符串stringByAddingPercentEncodingWithAllowedCharacters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32433461/