0

Hello

I have the following:

String somestring="203/9834/345";
somestring.replace("/","");
System.out.println(somestring);

But it does not remove the slashes. How can I remove them?

Thanks

3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by riahc3
1

Strings in Java are immutable - ie their content never changes. The replace method therefore does not change the original String. It returns a new String that has the replacements made...

      String somestring="203/9834/345";
      String replaced = somestring.replace("/","");
      System.out.println(replaced);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.