[Solved] how to replace some character’s of String


You can use string replace method. see below

String number = +9231235410;
String newNumber = number.replace("+92","0");

EDIT:

this one is base on your code

 private String modifyNumber(String num) {
            if (num.startsWith("+92")) {
                num = num.replaceFirst("\\+(92)", "0");}
            return num;}

Note:

  • In java, you need to have double backslash since the \ is a unique
    java character.
  • Java strings are immutable method. you need to assign it to a variable to have the result. num = num.replaceFirst("\\+(\\d{2})", "0")

3

solved how to replace some character’s of String