I am trying to replace characters in a string
for (String word : stringArray){
int k = 33;
char d ="";
while (k < 64){
char c = k;
word = word.replace(c, ""); // THIS LINE GIVES AN ERROR
k++;
}
}
I am trying to get rid of all the non-letter characters between ASCII id 32 (!) and ASCII id 64 (@), inclusive. I am using stringid.replace(char, char) as suggested here.
However, "" in the second argument of replace is being treated as a string in Eclipse, which is giving an error as "type mismatch" (since replace expects arguments which are both characters).
I have tried '' instead of "" but that doesn't seem to fix the problem. What should I do? Thanks in advance.
EDIT: changed word.replace(c, ""); to word = word.replace(c,""); . Thanks to commenter for pointing this out. However, the problem still occurs.