I’m using replace and replaceAll Java functions to replace strings in text files.
I’ve some issues with some symbols occurring in my text file, such as " and \
Let’s say I have to remove the ” from “blablabla”, what should i use ? I’m currently using this line but it doesn’t work:
fields[i] = fields[i].replaceAll("\\"blablabla\\"", "");
thanks
It’s because
replaceAlluses regex, and in regex\which is written as\\in a Java String has a special meaning. Incidentally, that meaning is also to escape characters.Use
replaceto avoid that, as replace only checks for simple equality. Also, it’s probably faster.