Powershell: Higher version of Unicode is not supported

Created on 10 Sep 2020  路  4Comments  路  Source: PowerShell/PowerShell

Steps to reproduce

[char]'皓徎'
[char]'0x293FB'

Expected behavior


Actual behavior

image


Environment data


Issue-Question Resolution-Answered

Most helpful comment

A .NET char is documented

Represents a character as a UTF-16 code unit.

If a unicode character cannot fit into a single UTF-16 code point then it must be represented by multiple chars when used in a string. Technically it can represent any value between 0 and 65535 ([UInt16]::MaxValue) but your character exceeds that size.

For example 皓徎 is part of the CJK Unified Ideographs Extension B set and the UTF-16 encoded byte value of that is 0x64 0xD8 0xFB 0xDF. This is known as a surrogate pair in UTF-16.

You might consider using the new Rune type that is designed to handle unicode values. Otherwise we would need to know more about what you are trying to achieve here to help you reach your goal.

All 4 comments

Do you mean "u{293FB}"`?

A .NET char is documented

Represents a character as a UTF-16 code unit.

If a unicode character cannot fit into a single UTF-16 code point then it must be represented by multiple chars when used in a string. Technically it can represent any value between 0 and 65535 ([UInt16]::MaxValue) but your character exceeds that size.

For example 皓徎 is part of the CJK Unified Ideographs Extension B set and the UTF-16 encoded byte value of that is 0x64 0xD8 0xFB 0xDF. This is known as a surrogate pair in UTF-16.

You might consider using the new Rune type that is designed to handle unicode values. Otherwise we would need to know more about what you are trying to achieve here to help you reach your goal.

Oh I also forgot to mention, you can see that your character uses 2 chars by running '皓徎'.Length. It will output 2 as String.Length just returns the number of chars it used for the string and it doesn't take into account things like surrogate pairs or other composite glyphs in Unicode.

This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Was this page helpful?
0 / 5 - 0 ratings