开发者

How do I remove '\' characters from my NSString

/images/content/开发者_如何学编程booking_thumbs_uk/s_kl/50000/THB_999_H54007.jpg

changes to:

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


    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

Be very careful, because inside the source code between "..." the backslash has a special meaning. In order to represent an honest backslash, you need to double it, like "\\".


You can use newString = [oldString stringByReplacingOccurrencesOfString:@"\\" withString:@""];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜