user2210620
user2210620

Reputation: 315

JAVA toLowerCase() is getting symbols

I got a problem with this symbol — (not -). When I use tolowercase() function, it shows ���. I don't know how to fix this. Please help. Thank you.

public String content = "noise—tap, tap—plash, plash—as"; 
this.content = this.content.toLowerCase();
System.out.println(this.content); 

Output: noise���tap, tap���plash, plash���as

Upvotes: 3

Views: 257

Answers (1)

llogiq
llogiq

Reputation: 14541

The output in your case depends on three things.

  1. The charachter set of the source code (BTW. in my humble opinion you should use UTF-8)
  2. The lowercase replacement of the — character (on my system, this is the '–' character, but your mileage may vary, there are some broken unicode implementations on this planet)
  3. The predefined character set of your console (On my Linux box, this is also UTF-8, but e.g. many windows boxes or other legacy systems may define other character sets. If the '–' character is not available in this set, you'll get the replacement characters in your output.#

Edit: I'd guess that 3. is the most likely culprit. You can look at the system property file.encoding for confirmation.

Upvotes: 5

Related Questions