1

I want to search a particular char from string without any loop and then i want to insert new char after that.

String a = "my%name%is%";

I want to find "%" and then i want to insert "?" char.

Output result:

a = "my%?name%?is%?";
1
  • You can't do this reasonably without looping. Any other function you could use to do this will most likely loop internally. Commented Mar 30, 2016 at 11:53

2 Answers 2

1

Use replace(char a,char b).

void replaceString(){
   String a = "my%name%is%";
   System.out.printlnt(a.replace("%","%?"));
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can also use replaceAll(String regex, String replacement)

String a = "my%name%is%";
System.out.println(a.replaceAll("([.*^%])", "%?"));//prints my%?name%?is%?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.