Unknown escape sequence "\040" in Objective-C
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:@"\\ "];
精彩评论