[英]How to remove double quote characters from a String?
My server json result is "abcde"
(it contains "
). 我的服务器json结果是
"abcde"
(它包含"
)。
How to remove "
? This is not working. 如何删除
"
?这不起作用。
System.out.print(result.replaceAll("\"\",""));
不要使用replaceAll(String regex, String replacement)
因为它接受正则表达式作为第一个参数(你不需要它),使用replace(CharSequence target, CharSequence replacement)
代替:
System.out.print(result.replace("\"",""));
尝试使用:
System.out.println(result.replace("\"",""));
尝试这个:
System.out.print("abcde".replaceAll("\\"",""));
I am not sure why the other solutions do not work, but just for the sake of being thorough, can you check with replaceAll("\\\\\\"",""));
我不确定为什么其他解决方案不起作用,但只是为了彻底,你可以检查
replaceAll("\\\\\\"",""));
Since replaceAll
method expects a regular expression! 因为
replaceAll
方法需要正则表达式!
Seeing that the other answers don't work for you, you could always remove the "
manually. By removing the first character and the last one. 看到其他答案对您不起作用,您可以随时删除
"
手动。删除第一个字符和最后一个字符。
String str = "\"abdc\"";
str.substring(1, str.length()-1);
It a bit of a hack, not sure if has the same efficiency of replace. 这有点像黑客,不确定是否具有相同的替换效率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.