2015-09-07 50 views
2

我有一個字符串變化NSURL字符串通過該方法stringByAddingPercentEncodingWithAllowedCharacters

https://www.example.com/abc/Gesture-abc-mobile-app_%257E0177cae9d41f573e5f?source=rss 

當我在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 

告訴我爲什麼會發生這種情況...

+1

垃圾進垃圾了嗎? – trojanfoe

回答

0

有你的字符串末尾多餘的字符 - 回車和空格確切的說:

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 

末刪除垃圾和你會得到想要的結果。

+1

謝謝,我如何刪除垃圾? – jaskiratjd

+0

你最初如何得到字符串?顯示代碼... –

+0

<__ NSArrayM 0x7ff70142a990>( { link =「https://www.example.com/jobs/Create-simple-mobile-app-Android_%7E01d56c3726006e7862?source=rss\n」; title =「創建簡單的移動應用Android - Upwork \ n」; }, { link =「https://www.example.com/jobs/Native-IOS-Android-App-Project_%7E01589e11a89d7c5620?source= rss \ n「; title =」原生IOS & Android應用程序項目 - 上班\ n「; }, – jaskiratjd