[英]Formatting string problems with replaceAll in Java
我有一个字符串:
String strung = (1.0√(10.0))/1.0
拨打以下电话后:
strung = strung.replaceAll(".0","");
strung = strung.replaceAll("1√","√");
我不希望得到这个:
(√())/1
我只需要获取以下内容,但很难进行设置
√10
感谢您的任何建议
使用replace
,而不是replaceAll
。
replaceAll
的参数分别解释为正则表达式和正则表达式替换。 因此, .
被解释为“任何字符”。
replace
从字面上接受参数,如"."
中所示"."
仅匹配字符串中的句点。
当然,您也可以继续使用replaceAll
,但可以转义.
:
strung = strung.replaceAll("\\.0","");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.