Replace function in java

In the below program we are replacing “\\” (2 backslash) with (4 backslashes). Actually \(backslash) is used for escaping characters. Here we have to escape backslash only. so only 8 backslashes are used to get 4 backslashes.

Program:

package god;

public class ReplaceFunction {

	public static void main(String[] args) {
		String naveen = "javadomain\\naveendra\\eversoftindia";
		System.out.println(naveen);
		String cool="\\\\\\\\\\\\\\\\";
		System.out.println("after replacements using
               replace function "+naveen.replace("\\", cool));
	}

}

 

 

Output:

javadomain\naveendra\eversoftindia
after replacements using replace function javadomain\\\\\\\\naveendra\\\\\\\\eversoftindia

746 total views, 2 views today

About Mirthbees 679 Articles
Blogger, Innovator, Developer and Enterpreneur. Founder of GuruRecharge, Readymade online recharge script. Lead Developer in Bookrate.in

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.