11

I am url encoding a string of text to pass along to a function. However, it encodes the second space in a double-space as "%A0". This means that when I decode the string, the "%A0" is displayed as a question mark in a black box.

I really just need to be able to remove the extra space, but I'd like to understand what is causing this and how to handle it correctly.

For example:

Something  Something else

Encodes to:

Something+%A0Something+else
NoNaMe
  • 6,020
  • 30
  • 82
  • 110
rybo
  • 1,161
  • 2
  • 10
  • 14
  • possible duplicate of [URL encoding the space character: + or %20?](http://stackoverflow.com/questions/1634271/url-encoding-the-space-character-or-20) – AJ. May 31 '11 at 19:58
  • 4
    @AJ: This is not the same. Please read the question. The OP wants to know why `%A0` is appearing in the encoded values, not whether to use `+` or `%20` to escape spaces. – Richard Marskell - Drackir May 31 '11 at 20:01

4 Answers4

19

%A0 indicates a NBSP (U+00A0). + indicates a normal space (U+0020). The NBSP displays as a replacement character (U+FFFD) because the encoding of the character does not match the encoding of the page, so its byte sequence is not valid for the page.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
4

A quick Googling shows that %A0 is the non-breaking space character or   in html. A + is the form-encoding for a standard space character.

Source

Paul DelRe
  • 4,003
  • 1
  • 24
  • 26
1

The problem you're having is that the second "space" is not really a space, it's a character that that font doesn't have a glyph (I think that's the term) to represent (hence the black box with the question mark). %A0 is the escape code for that character. Your code is technically handling it correctly, I think the problem is with whatever is generating the string in the first place.

1

If I refer to the chart on this page, %A0 is not a space. %20 is the space caracter's encoded value.

Stephane Gosselin
  • 9,030
  • 5
  • 42
  • 65