开发者

How do I remove '\' characters from my NSString

开发者 https://www.devze.com 2023-01-13 23:18 出处:网络
/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.jpgNSString* original=@\"\\\\/images\\\\/conte

/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

精彩评论

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