如何使用java将点(。)替换为逗号(,)
问题描述:
我有一个字符串str = 12,12
我想用(逗号)替换。(点)进行十进制数计算,
目前我正在尝试这个:
I am having a String str = 12,12
I want to replace the ,(comma) with .(Dot) for decimal number calculation,
Currently i am trying this :
if( str.indexOf(",") != -1 )
{
str.replaceAll(",","\\.");
}
请帮助
答
你的问题不在于匹配/替换,但是String是不可变的,你需要分配结果:
Your problem is not with the match / replacement, but that String is immutable, you need to assign the result:
str = str.replaceAll(",","."); // or "\\.", it doesn't matter...