开发者

Unknown escape sequence "\040" in Objective-C

开发者 https://www.devze.com 2023-02-12 06:22 出处:网络
I need to replace something like \"abc%20def%20xyz\" with \"abc\\ def\\ xyz\". I used this function that works fine.

I need to replace something like "abc%20def%20xyz" with "abc\ def\ xyz". I used this function that works fine.

string2 =[string2 stringByReplacingOccurrencesOfString:@"%20" withString:@"\ "];

However, I got warning saying

Unknown escape sequence "\040".

What开发者_如何转开发's wrong with this, and how can I remove this warning?


The backslash in the end string is escaping the space character, which isn't valid. To do what you want, you need to escape the backslash:

string2 =[string2 stringByReplacingOccurrencesOfString:@"%20" withString:@"\\ "];

0

精彩评论

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