如何从NSString中删除'\'字符

时间:2010-08-27 15:47:28

标签: objective-c

/images/content/booking_thumbs_uk/s_kl/50000/THB_999_H54007.jpg

更改为:

/images/content/booking_thumbs_uk/s_kl/00000/THB_999_H2470.jpg

2 个答案:

答案 0 :(得分:2)

    NSString* original=@"\\/images\\/content\\/booking_thumbs_uk\\/s_kl\\/50000\\/THB_999_H54007.jpg";
    NSString* removed=[original stringByReplacingOccurrencesOfString:@"\\" withString:@""];
    NSLog(@"%@",removed);  // shows /images/content/booking_thumbs_uk/s_kl/00000/THB_999_H2470.jpg

要非常小心,因为在“...”之间的源代码中,反斜杠具有特殊含义。为了表示诚实的反斜杠,你需要加倍,比如“\\”。

答案 1 :(得分:1)

您可以使用newString = [oldString stringByReplacingOccurrencesOfString:@"\\" withString:@""];