我正在尝试更换'\\'
with '/'
在java(Android)中,这似乎不起作用!
String rawPath = filePath.replace("\\\\", "/");
这有什么问题吗?我已经转义了“\”并尝试转义“/”但没有用。原始字符串没有任何变化。
filePath = abc\\xyz(not after escaping two \\, the original string is with two \\)
rawPath = abc \ xyz
expected = abc/xyz
这样做的正确方法是什么? (另一个Windows文件到Android路径转换问题)
使用时String.replace(String, String)
反斜杠不需要转义两次(即使用时replaceAll
- 它处理正则表达式)。所以:
String rawPath = filePath.replace("\\", "/");
或者使用char
版本:
String rawPath = filePath.replace('\\', '/');
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)