Loading

Considerations for Using the String Class substring Method with Surrogate Pairs

Fecha de publicación: Mar 24, 2026
Descripción

Surrogate pair characters are interpreted as a single character by combining a "high surrogate" and a "low surrogate."
Therefore, for example, if you use the substring(0, 1) method on a String variable containing a single surrogate pair to extract only the high surrogate, it will not be interpreted as a valid surrogate pair, and the character cannot be retrieved correctly.

Solución

When handling surrogate pair characters using methods such as substring, the implementation must retrieve two values (the high and low surrogates) for a single character. 
In the example above, this should be implemented as substring(0, 2).

Número del artículo de conocimiento

000395737

 
Cargando
Salesforce Help | Article