-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
  • 41,816
  • 6
  • 58
  • 77
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
  • 41,816
  • 6
  • 58
  • 77
0

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

Shubham Goel
  • 1,768
  • 15
  • 24
0

try above code

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

  if(priceString.contains(",")){
      newPriceString = priceString.replaceAll(",",".");
  }
Omkar
  • 2,810
  • 1
  • 21
  • 38