I have a problem with strings saved in a database, like this for example: \"311\\315_316\\336_337\"
. They have only one backslash and this is a problem in java. Wh
You could also use Unicode \ = \u005c
Example: "Folder\u005cSubfolder1\u005cSubfolder2"
Would result in the string "Folder\Subfolder1\Subfolder2"
You can see the full table here: http://jrgraphix.net/r/Unicode/0020-007F
in java, backslash \
has a special meaning. in order to remove it, escape it with another backslash \\
try this:
s.replaceAll("\\", "\\\\");
The data in the database is OK, and you don't have to replace anything. String literals, written directly in the Java code, must have their backslash escaped by another backslash:
String s = "311\\315_316\\336_337";
System.out.println(s); // prints 311\315_316\336_337
But if you get those values from the database, you don't have anything to do:
String s = resultSet.getString(1);
System.out.println(s); // should print 311\315_316\336_337
In java strings, the backslash character is a control character. If you wish to include a literal backslash in a string, you must escape it with another backslash. e.g. "\\"