0

I have to test few 10 digit values.

          Value: 124324*3213*4324*44*3123**13*
         Expected value: 1243243213432444312313

So far, I have been able to replace the stars using str.replace() function. But I'm unable to remove the white spaces created after removing the star ?.

2 Answers2

2

Try something like this:

String value = "124324*3213*4324*44*3123**13*".replace("*", "");
Mateusz Korwel
  • 1,118
  • 1
  • 8
  • 14
2

Remember that strings are immutable in Java so you have to assign value again:

String s = "124324*3213*4324*44*3123**13*";
s = s.replaceAll("\\*", "");

"\\*" - is a regular expression, but you don't need to worry about that. The important part is that "*" sign has special meaning in regular expressions, so you have to escape it with a backslash. To create a backslash character in Java string you have to use "\\" - so the final expression is "\\*".

Keammoort
  • 3,075
  • 15
  • 20