I'm trying to replace "C:\FREQ\" with a whitespace.
String trimmed = files[i].toString().replace("C:\FREQ\", "");
But eclipse gives an error on the "C:\FREQ\" , saying Invalid escape sequence. What do I need to do?
You need to escape the backslashes:
String trimmed = files[i].toString().replace("C:\\FREQ\\", "");
Backslashes within Java text literals (String or char) are used for escape sequences such as \t
(tab), \n
(line feed) etc. To get an actual backslash, you need to just use \\
.
See the Java language specification section 3.10.6 for more details.
See more on this question at Stackoverflow