1

I'm receiving a string from the server and it has the special characters in code. Here's the example:

"El usuario o las contrase\UOOOOfffda no son v\UOOOOfffdlidos"

The first one should be an "ñ" and the second one "á"

I know it's not complicated but I can't find the answer. How can I get the string with the special characters correctly formatted?

jscs
  • 63,694
  • 13
  • 151
  • 195
Jaime Alcántara Arnela
  • 2,062
  • 5
  • 25
  • 56

2 Answers2

3

Unicode U+FFFD (in your string, displayed as UTF-32 \U0000fffd) is "�", the replacement character. It is often substituted in strings when a system encounters unrecognized characters.

This character really shouldn't appear in string data since its purpose is to indicate an error in displaying or interpreting the string. Since your server is sending you that character for both ñ and á, there is no way to retrieve the correct character.

How are you "receiving" this string? It could be that you are accessing the server incorrectly so it isn't sending you an unmodified string.

Max
  • 21,123
  • 5
  • 49
  • 71
1

Unicode for those characters should look like this:

@"accented-a is \u00f1, and tilda-n is \u00e1"

But it's not clear what you're getting from the server makes any sense. The objective-c literal must have a lowercase leading "u" followed only by valid hex digits (0-9 and a-f). I don't see a transformation that changes the literals you have to the ones you expect.

Once the characters are formatted properly, the built-in classes will just work, for example, assigning the string to a label's text property will show the user a nice glyph.

danh
  • 62,181
  • 10
  • 95
  • 136