Answers for "java replace all instance of one character with a different character in a string"

2

replace all occurrences of a character in a string java

String phrase = "An_Apple_A_Day_Keeps_The_Doctor_Away";
System.out.println(phrase.replaceAll("_", " ");
// prints 'An Apple A Day Keeps The Doctor Away'
Posted by: Guest on August-03-2021
0

how to replace a character with another character in a string in java

public class JavaExample{
   public static void main(String args[]){
	String str = new String("Site is BeginnersBook.com");

	System.out.print("String after replacing com with net :" );
	System.out.println(str.replaceFirst("com", "net"));

	System.out.print("String after replacing Site name:" );
	System.out.println(str.replaceFirst("Beginners(.*)", "XYZ.com"));
   }
}
Posted by: Guest on April-05-2021

Code answers related to "java replace all instance of one character with a different character in a string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language