My program reads some strings from file which have to be post processed. The original text in the file looks like
A1DY^
BLKSS^
"GH67^"^
Where ^
is the space character I used to demonstrate. As you can see all words in the file end with space. Some words are in double quote. I want to store these strings in my program
A1DY
BLKSS
GH67
In other words, I want to trim all spaces and double quotes. If I use str.trim();
it will remove the last space. So, the third line will be "GH67^"
. I also used str.replaceAll("^\"|\"$", "");
to trim the double quotes. The result is GH67^
. That means, I have to trim it again.
Is there any better way to remove all spaces and double quotes at once? Note that I don't want to extract alphanumeric characters. I want to trim special characters.