如何用字符串替换反斜杠.
输入源字符串:
sSource = "http://www.example.com\/value";
Run Code Online (Sandbox Code Playgroud)
在上面的String中我想用"/"替换"\ /";
更换后的预期输出:
sSource = "http://www.example.com/value";
Run Code Online (Sandbox Code Playgroud)
我从第三方获取Source String,因此我可以控制String的格式.
这就是我尝试过的
试验1:
sSource.replaceAll("\\", "/");
Run Code Online (Sandbox Code Playgroud)
异常索引1附近出现意外内部错误
试验2:
sSource.replaceAll("\\/", "/");
Run Code Online (Sandbox Code Playgroud)
没有例外,但没有做必要的替换.什么都不做.
试验3:
sVideoURL.replace("\\", "/");
Run Code Online (Sandbox Code Playgroud)
没有例外,但没有做必要的替换.什么都不做.
我的问题很简单:
如何用""取代"\ " ???
我试过这个:
str.replaceAll("\\", "");
Run Code Online (Sandbox Code Playgroud)
但我得到例外
08-04 01:14:50.146: I/LOG(7091): java.util.regex.PatternSyntaxException: Syntax error U_REGEX_BAD_ESCAPE_SEQUENCE near index 1:
Run Code Online (Sandbox Code Playgroud) 我已生成一个文件名并存储在尝试使用的字符串变量路径中
path=path.replaceAll('\','/')
Run Code Online (Sandbox Code Playgroud)
但这不起作用