用`'`替换出现的NSString到`\'`

时间:2015-04-22 13:22:11

标签: ios objective-c replace nsstring

我有一个NSString,我试图替换特殊字符。我的部分字符串如下所示:

我已将'替换为\'

3 个答案:

答案 0 :(得分:7)

注意: \是目标c中的转义字符。

 NSString *s = @"This is Testing Mode and we are testing just Details of this Ladies' Market place";


NSString *r = [s stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];

答案 1 :(得分:4)

NSString *str = @"'Hello'";
str = [str stringByReplacingOccurrencesOfString:@"'" withString:@"\\"];

答案 2 :(得分:-1)

public class Foo
{
public string MemberId {get; set;} 
public string Email {get; set;} 
public string Name {get; set;} 
public string RedirectUrl {get; set;} 
}
public ActionResult SendNotification(Foo foo)

使用转义字符" \",我们可以删除不需要的字符。转义字符旁边的字符(" \")将被忽略/转义。