I have problem of replacing "…" in java. This is driving me crazy.
It seems that java can't recognize "…" by replace method. What should I try?
I tried
line = line.replace("…", "");
But it doesn't work.
I have problem of replacing "…" in java. This is driving me crazy.
It seems that java can't recognize "…" by replace method. What should I try?
I tried
line = line.replace("…", "");
But it doesn't work.
Try this redirect: Eclipse character encoding
This isn't exactly related, but it is a setting in eclipse that you should check nonetheless.
You are likely having a Unicode translation issue. Try using "\u2026" instead of the literal ellipsis character: http://www.fileformat.info/info/unicode/char/2026/index.htm and Creating Unicode character from its number. You can not always control how unicode characters will be interpreted in your source code beyond the ASCII set. It is generally a good idea to use escapes for such characters.
The String.replaced only char in the older javas, but nowadays also can replace strings (literally without regex patterns).
The problem you might have encountered, is that of wrong encoding. The encoding of the .java source in the editor versus the compiler's encoding. If you pasted the ellipsis, something might go wrong too.
So use the escaped ASCII representation. You can find the code in the system accessory Character Map:
line = line.replace("\u2026", "");
Also the line must have been read with the correct encoding. Do not use FileReader, but use another class where one can add explicitly the encoding.
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(file), "UTF-8"));
Instead of the encoding UTF-8 it could be some platform dependent code like Cp1252.