0

我可以替换" "URL 中的空格字符,但是当其中包含非英文字符时,它会返回错误的 URL。例子:

我正在使用的网址:www.mostlifeclub.com/MostWeb/img/gallery2/7göller (2).jpg

我正在使用的代码:

tempUrl = 
[tempUrl stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

它返回给我的是:

http://www.mostlifeclub.com/MostWeb/img/gallery2/7göller%20(1).jpg

(其中添加了一些汉字)

因此,我无法在我的照片库中显示照片。

可能是什么问题?

4

1 回答 1

4

你试过 stringByAddingPercentEscapesUsingEncoding 方法吗?

NSMutableString *string = [[NSMutableString alloc] init];

[string setString:@"http://urlWithStrång€Characters"];

NSURL *url = [[NSURL alloc] initWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
于 2013-01-31T08:31:30.477 回答