How to use the UNICHAR function
What is the UNICHAR function?
The UNICHAR function in Excel returns the Unicode character corresponding to a given Unicode code point number.
Table of Contents
1. Introduction
What is UNICODE?
Unicode provides a universal character set and encoding schemes to represent text consistently across computing technologies and interfaces. It supports internationalization and localization needs which enables global websites and apps to display text and accept input in any language script like Arabic, Chinese, Hindi etc. without restrictions.
- Provides a unique number for every character, regardless of the platform, device, application, or language.
- With the capacity to represent over 1.1 million characters, Unicode encompasses all the world's languages and writing systems in one unified encoding standard.
- Allows data exchange and processing of text in any language combination.
- Maintained by the Unicode Consortium and coordinated with ISO standards.
- Common Unicode encodings are UTF-8, UTF-16, and UTF-32, which provide variable length or fixed width representations.
What is a character set?
A character set is a defined collection of textual characters used to represent writing systems, symbols, and numbers. They provide a mapping between numeric codes and human-readable characters. Common character sets include ASCII, Unicode, UTF-8, Latin-1, etc.
What is the difference between the UNICHAR function and the CHAR function?
UNICHAR takes a Unicode code point as input and returns the Unicode character for that code point. CHAR takes an ANSI code value as input and returns the ANSI character (windows).
What is the difference between UNICODE and ANSI?
ANSI uses 8-bit encoding, unicode uses variable width encoding of 8-bit to 32-bit. ANSI is limited to English, unicode enables internationalization and localization. ANSI predates Unicode and is a legacy standard, Unicode is a newer standard.
The UNICHAR and the UNICODE functions let you convert between Unicode characters and their underlying code point representations.
2. Syntax
UNICHAR(number)
number | Required. The Unicode number for which you want the corresponding character. |
3. Example
UNICHAR function converts a Unicode code point value to its corresponding Unicode character.
Formula in cell C3:
This results in #VALUE! because 0 is not a valid Unicode code point.
Formula in cell C4:
The UNICHAR function accepts a numeric Unicode code point which is 65 in this example. For code point 65, the corresponding Unicode character is 'A'. UNICHAR(65) evaluates to 'A'.
Formula in cell C4:
Returns "A", the Unicode character for code point 65
Formula in cell C5:
Returns "Z", the Unicode character for code point 90
Formula in cell C6:
Returns "a", the lowercase "a", the Unicode character for code point 97.
Formula in cell C7:
Returns "z", the lowercase "z", the Unicode character for code point 122
Formula in cell C8:
Returns "ÿ", the Unicode character for code point 255
Formula in cell C9:
Returns "ř", a Czech letter, the Unicode character for code point 345
Formula in cell C10:
Returns "ʎ", a phonetic symbol, the Unicode character for code point 654
Formula in cell C11:
Returns "β", the Greek letter beta, the Unicode character for code point 976
Formula in cell C12:
Returns "Ұ", a Cyrillic letter, the Unicode character for code point 1200
Formula in cell C13:
Returns "ڬ", an Arabic letter, the Unicode character for code point 1500
Formula in cell C14:
Returns "✏", a pencil icon, the Unicode character for code point 9999
Formula in cell C15:
Returns "耀", a Chinese character, the Unicode character for code point 32768
4. UNICHAR Function not working
The UNICHAR function returns:
- #N/A error value if data type is not valid.
- #VALUE! error
- if number is 0 (zero).
- if outside the range.
5. How to convert from formal Unicode notation U+XXXX to its corresponding Unicode character
The following formula converts a hexadecimal unicode to the matching unicode character. Converting hexadecimal Unicode to matching Unicode characters can be useful in several scenarios like:
- Web development and HTML: When you need to include special characters or symbols in HTML that aren't easily typed on a keyboard. For ensuring proper character encoding in web pages, especially for multilingual content.
- Programming and software development: When working with internationalization (i18n) and localization (l10n) in software. For handling text processing in languages with non-ASCII characters.
- Data processing and analysis: When dealing with datasets that contain encoded characters from various languages or symbol sets. For cleaning and standardizing text data that may contain Unicode escape sequences.
- Font and typography work: When designing or working with fonts that include extended character sets. For verifying the presence of specific glyphs in a font.
- Cryptography and encoding: In some encryption or encoding schemes that use Unicode characters.
- Database management: When working with databases that store data in Unicode format but display hexadecimal representations.
- Text editors and IDEs: For inputting special characters in code or text that aren't directly available on the keyboard.
In Excel specifically, functions like UNICHAR can be helpful when you need to display or work with Unicode characters based on their code points, which might be stored or processed as numbers in your data.
Formula in cell C3:
Here is a brief explanation, there is a more detailed explanation below.
- MID(B3,3,99): This function extracts a substring from the value in cell B3. It starts at the 3rd character (skipping the first two characters). It attempts to extract up to 99 characters (or until the end of the string). This is likely used to remove a prefix (like "0x" or "U+") from a hexadecimal Unicode representation.
- HEX2DEC(...): This function converts the extracted hexadecimal string to a decimal number. It takes the result of the MID function as its input. For example, if B3 contained "U+1F600", the MID function would extract "1F600", and HEX2DEC would convert this to 128512.
- UNICHAR(...) Finally, this function takes the decimal number produced by HEX2DEC and returns the corresponding Unicode character. It converts the Unicode code point (in decimal) to its actual character representation.
This formula is useful when you have Unicode characters represented in hexadecimal format (like "U+1F600" for a smiley emoji) and you want to display the actual character in Excel. It effectively decodes the hexadecimal Unicode representation into the visible character.
Explaining formula
Step 1 - Remove two first characters from string (U+)
The MID function returns a substring from a string based on the starting position and the number of characters you want to extract.
Function syntax: MID(text, start_num, num_chars)
MID(B3,3,99)
becomes
MID("U+0045",3,99)
and returns "0045".
Step 2 - Convert hexadecimal to decimal
The HEX2DEC function converts a hexadecimal number to a decimal number.
Function syntax: HEX2DEC(number)
HEX2DEC(MID(B3,3,99))
becomes
HEX2DEC("0045")
and returns 69.
Step 3 - Convert unicode to character
The UNICHAR function calculates a character based on a Unicode number.
Function syntax:
UNICHAR(HEX2DEC(MID(B3,3,99)))
becomes
UNICHAR(69)
and returns "E".
Useful links
UNICHAR function - Microsoft support
UNICODE - wikipedia
Functions in 'Text' category
The UNICHAR function function is one of 29 functions in the 'Text' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form