I use code blow to replace \\ with \
NSString *str =@"\\u597d\\u6f02\\u4eae\\u7684\\u5a5a";
str= [str stringByReplacingOccurrencesOfString: @"\\\\" withString: @"\\" ];
but it looks like stringByReplacingOccurrencesOfString does not work.
Both of them output
\u597d\u6f02\u4eae\u7684\u5a5a
Welcome any comment
This is because the source string does not contain double slashes: all doubled slashes are consumed by the compiler in the process of creating your string constant, and replaced by single slashes to arrive at your final string:
When you use a slash inside a string constant, two slashes are needed to represent one slash. When you use a slash inside a string constant that you pass to a regular expression, you need four slashes: two of the four will be consumed by the compiler, and then one of the remaining two will be consumed by the regex compiler.
Here is your example that does what you expected it to do:
The output looks like this: