Saltar al contenido
uencoder

Cómo a Codificar Unicode Caracteres

Convertir Unicode characters into various representations such as escape sequences, code points, and UTF-8 bytes.

问题

You necesitar a represent non-ASCII Unicode caracteres (como emoji o CJK caracteres) en sistemas ese solo aceptar ASCII.

Requisitos previos

  • Understanding of Unicode code points
  • Familiarity with UTF-8 encoding

Pasos

  1. 1. Find the code point

    Look up the Unicode code point of your character. For example, the euro sign € is U+20AC. The code point is a scalar value that uniquely identifies the character in the Unicode standard.

    entrada
    €
    输出
    U+20AC
  2. 2. Convert to the target representation

    For JavaScript strings, use \u20AC or \u{20AC}. For UTF-8 bytes, encode as 0xE2 0x82 0xAC. For HTML, use € or €. Choose the representation your target system expects.

    entrada
    €
    输出
    JS: \u20AC | UTF-8: E2 82 AC | HTML: €
  3. 3. Verify round-trip fidelity

    Decode the representation back to the original character and compare. Characters outside the Basic Multilingual Plane (above U+FFFF) require surrogate pairs in UTF-16, so pay extra attention to emoji and rare scripts.

    entrada
    \u20AC
    输出
    €

Resultado esperado

Un correct ASCII-seguro representation de el Unicode carácter ese decodes back a el exact original.

Errores comunes

Using \uXXXX for characters above U+FFFF without surrogate pairs
Use the \u{XXXXX} brace syntax in JavaScript or compute the surrogate pair manually for older environments.
Confusing UTF-8 byte count with code point value
UTF-8 uses 1-4 bytes per character. The byte values are not the same as the code point. Use a proper encoder.

Solución de problemas指引

  • If a character shows as two boxes, it was split into surrogate pairs incorrectly. Use a UTF-8-aware tool.
  • Check that your file editor saves as UTF-8 without BOM to avoid hidden bytes.

Límites de seguridad

  • Unicode encoding does not sanitize input. Be aware of homoglyph attacks where visually identical characters from different scripts are used to deceive.

Herramientas relacionadas

Términos relacionados

参考链接