在Android Studio中使用Android应用
但是在replaceAll上有一个弹出窗口,上面写着:“结果会被忽略”
String priceString = mPriceEditText.getText().toString().trim();
if(priceString.contains(",")){
priceString.replaceAll(",",".");
}
我该如何修复此代码?
答案 0 :(得分:4)
字符串在Java中是不可变的,因此priceString.replaceAll(",",".")
无法更改priceString
。相反,它会返回您忽略的新字符串。
您需要将返回的字符串分配给某些内容,例如:
priceString = priceString.replaceAll(",",".");
答案 1 :(得分:0)
只是priceString.replace(",",".")
为我工作
答案 2 :(得分:0)
try above code
String priceString = mPriceEditText.getText().toString().trim();
final String newPriceString;
if(priceString.contains(",")){
newPriceString = priceString.replaceAll(",",".");
}