12

I don't understand whenever I save any string that contains ñ it changes to ñ. Even in the database the ñ is changed to ñ.

Examples:

  • ñ becomes ñ.
  • Niño becomes Niño.

I don't have any clue what causes this problem or where the problem is coming from. Please help. Thanks in advance.

Jeremy
  • 22,188
  • 4
  • 68
  • 81
NinjaBoy
  • 3,715
  • 18
  • 54
  • 69
  • 1
    I suspect it's a database issue, due to "even in the database..."; inspecting the *actual value* inserted would likely confirm/disprove this. –  May 29 '12 at 00:52
  • The database is probably not UTF-8. – Tony Ennis May 29 '12 at 01:48

4 Answers4

12

Character ñ (U+00F1) is encoded using UTF-8 as the two bytes 11000011 10110001 (0xC3 0xB1).

These two bytes are decoded using ISO 8859-1 as the two characters ñ.

So, you are most likely using UTF-8 to encode the character as bytes, and ISO 8859-1 (Latin-1, as guessed by Sajmon) to decode the bytes as characters.

Nathan Ryan
  • 12,893
  • 4
  • 26
  • 37
  • May I be curious and ask how you worked out the binary encoding/ which source you used to get it? – Philippe May 30 '12 at 01:14
  • 2
    @Philippe: I used the standard definition of UTF-8. Wikipedia has a nice page http://en.wikipedia.org/wiki/UTF-8#Description – Nathan Ryan May 30 '12 at 07:06
6

Character encoding problems, for sure. Make sure that the database, the web pages, content charset, java files, string encoding, etc. are all using the exact same encoding - for instance, UTF-8.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
5

Your string has a wrong encoding. It's UTF-8 but you need other, uhm Latin-1? You need decode.

Check this

Hope it help you.

Community
  • 1
  • 1
Simon Dorociak
  • 33,374
  • 10
  • 68
  • 106
3

It is a character encoding issue, you need to check if your whole stack from writer to reader is set to UTF-8.

Check out this discussion, it might contain some info to help you:

Community
  • 1
  • 1
Philippe
  • 446
  • 2
  • 12