2

我有以下内容:

modifiedTitle = @"Léon";
modifiedTitle = [modifiedTitle stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", modifiedTitle);

转换后,它现在显示为L%C3%A9on.

当我运行以下命令时,它不会将其转换回来:

NSMutableString *searchText = [NSMutableString stringWithString:modifiedTitle];
[searchText stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", searchText);

它仍然显示为L%C3%A9on

有谁知道为什么?

4

1 回答 1

4

因为stringByReplacingPercentEscapesUsingEncoding:返回一个新字符串。试试这个:

NSMutableString *searchText = [NSMutableString stringWithString:modifiedTitle];
NSString *newText = [searchText stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"%@", newText);
于 2012-04-19T22:41:34.287 回答