cancel
Showing results for 
Search instead for 
Did you mean: 

unable to use .replaceAll method

Former Member
0 Kudos

Hi all,

since the .getPath() method return path in "C:\Folder\File.ext" format but java reads file path in "C:
Folder
File.ext" (actually there is double splace.. here Html is interpreting with newLine in forum page)format.

I have to replace those '\' with 'double \' using string.replaceAll method, but since \ is escape character i am not able to do this, please help.

Edited by: Sulochan on May 9, 2011 12:55 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I hope I get your question right: You want to replace the single backslashes with double backslashes?

Then the following java code does that for you:

String stringWithDoubleBackslashes = replace.all("\\\\", "\\\\\\\\");

As the other poster mentioned, the JavaDocs are of big help, if you can you might want to use the Apache Commons libraries for operations like that since they avoid pitfalls like those.

Answers (1)

Answers (1)

rolf_paulsen
Active Participant
0 Kudos

Hi,

javadoc of java.lang.String.replaceAll() is your friend.

Simply use java.util.regex.Matcher.quoteReplacement(yourstring)

Regards

Rolf