-1

Working on Android app in the Android Studio

But there is a pop-up window on replaceAll that says: "Result of this will be ignored"

 String priceString = mPriceEditText.getText().toString().trim();

if(priceString.contains(",")){
    priceString.replaceAll(",",".");
}

How could I fix this code?

Henry
  • 42,982
  • 7
  • 68
  • 84
Scooltr
  • 37
  • 7

3 Answers3

4

Strings are unmutable in Java, therefore priceString.replaceAll(",",".") cannot change priceString. Instead it returns a new string that you ignore.

You need to assign the returned string to something, e.g.:

priceString = priceString.replaceAll(",",".");
Henry
  • 42,982
  • 7
  • 68
  • 84
0

Just priceString.replace(",",".") worked for me

Shubham Goel
  • 1,962
  • 17
  • 25
0

try above code

String priceString = mPriceEditText.getText().toString().trim();
final String newPriceString;

  if(priceString.contains(",")){
      newPriceString = priceString.replaceAll(",",".");
  }
Omkar
  • 3,040
  • 1
  • 22
  • 42