Character Codes

Converting to and from character codes.

The Wolfram Language assigns every character that can appear in a string a unique character code. This code is used internally as a way to represent the character.

This gives the character codes for the characters in the string:

ToCharacterCode["ABCD abcd"]

(RefLink[FromCharacterCode, paclet:ref/FromCharacterCode]) reconstructs the original string:

FromCharacterCode[%]

Special characters also have character codes:

ToCharacterCode["α⊕Γ⊖∅"]

Generating sequences of characters.

This gives part of the English alphabet:

CharacterRange["a","k"]

Here is the Greek alphabet:

CharacterRange["α","ω"]

The Wolfram Language assigns names such as ∖[Alpha] to a large number of special characters. This means that you can always refer to such characters just by giving their names, without ever having to know their character codes.

This generates a string of special characters from their character codes:

FromCharacterCode[{8706,8709,8711,8712}]

You can always refer to these characters by their names, without knowing their character codes:

FullForm[%]

The Wolfram Language has names for all the common characters that are used in mathematical notation and in standard European languages. But for languages such as Japanese, Chinese, and Korean, there are thousands of additional characters, and the Wolfram Language does not assign an explicit name to each of them. Instead, it refers to such characters by standardized character codes.

Here is a string containing Japanese characters:

"数学"

In (RefLink[FullForm, paclet:ref/FullForm]), these characters are referred to by standardized character codes. The character codes are given in hexadecimal:

FullForm[%]

The notebook front end for the Wolfram System is set up so that when you enter a character, the Wolfram System will automatically work out the character code for that character.

Sometimes, however, you may find it convenient to be able to enter characters directly using character codes.

Ways to enter characters directly in terms of character codes.

For characters with character codes below 256, you can use \.nn. For characters with character codes above 256, you must use either \:nnnn or \|nnnnnn. Note that in all cases you must give a fixed number of hexadecimal digits, padding with leading 0s if necessary.

This gives character codes in hexadecimal for a few characters:

BaseForm[ToCharacterCode["Aàαℵ"],16]

This enters the characters using their character codes. Note the leading 0 inserted in the character code for α:

"Aàαℵ"

In assigning codes to characters, the Wolfram Language follows three compatible standards: ASCII, ISO Latin-1, and Unicode. ASCII covers the characters on a normal American English keyboard. ISO Latin-1 covers characters in many European languages. Unicode is a more general standard which defines character codes for several tens of thousands of characters used in languages and notations around the world.

A few ranges of character codes used by the Wolfram Language.

Here are all the printable ASCII characters:

FromCharacterCode[Range[32,126]]

Here are some ISO Latin-1 letters:

FromCharacterCode[Range[192,255]]

Here are some special characters used in mathematical notation. The empty boxes correspond to characters not available in the current font:

FromCharacterCode[Range[8704,8750]]

Here are a few characters from the Chinese/Japanese/Korean range:

FromCharacterCode[Range[30000,30030]]