简体   繁体   English

替换出现的NSString-iPhone

[英]Replace occurrences of NSString - iPhone

I have a long NSString in which I m trying to replace special characters. 我有一个很长的NSString,我正在其中尝试替换特殊字符。 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)"

I would like to replace all the \œ with "oe". 我想将所有\\ u0153替换为“ oe”。 I've tried: 我试过了:

[response stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];

but it doesn't work.... I don't understand why! 但这不起作用。。。我不明白为什么!

反斜杠是转义字符 ,因此,如果要在字符串文字中指定实际的反斜杠字符,则需要使用两个反斜杠。

NSString *new = [old stringByReplacingOccurrencesOfString: @"\\u0153" withString:@"oe"];

NSString是不可变的,因此该函数会生成一个必须存储的新字符串:

NSString *new = [old stringByReplacingOccurrencesOfString:@"\u0153" withString:@"oe"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM