替换出现的NSString - iPhone [英] Replace occurrences of NSString - iPhone
本文介绍了替换出现的NSString - iPhone的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个很长的NSString,我试图替换特殊字符。我的部分字符串如下所示:
I have a long NSString in which I m trying to replace special characters. Part of my string looks like this:
"veau (c\u00f4telette)","veau (filet)","agneau (gigot)","agneau (c\u00f4telette)","b**\u0153**uf (hach\u00e9)","porc (hach\u00e9)"
我想用oe替换所有\ u0153。我试过了:
I would like to replace all the \u0153 with "oe". I've tried:
[response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];
但它不起作用......我不明白为什么!
but it doesn't work.... I don't understand why!
推荐答案
反斜杠是转义字符,因此如果要在字符串文字中指定实际的反斜杠字符,则需要使用两个反斜杠。
The backslash is an escape character, so if you want to specify the actual backslash character in a string literal, you need to use two backslashes.
NSString *new = [old stringByReplacingOccurrencesOfString: @"\\u0153" withString:@"oe"];
这篇关于替换出现的NSString - iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文