on 05-09-2011 11:54 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
javadoc of java.lang.String.replaceAll() is your friend.
Simply use java.util.regex.Matcher.quoteReplacement(yourstring)
Regards
Rolf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.