TheLearner
TheLearner

Reputation: 19507

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

Upvotes: 2

Views: 2947

Answers (2)

livingtech
livingtech

Reputation: 3660

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

Upvotes: 1

Yuji
Yuji

Reputation: 34185

    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 "\\".

Upvotes: 2

Related Questions