Last active
August 29, 2015 14:01
-
-
Save sebgod/2980139451df3041f231 to your computer and use it in GitHub Desktop.
Lists all Unicode digits in a Console application, including astral characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AlllUnicodeDigits { | |
public static void Main() | |
{ | |
var unicodeEncoding = new UnicodeEncoding(!BitConverter.IsLittleEndian, false); | |
Console.InputEncoding = unicodeEncoding; | |
Console.OutputEncoding = unicodeEncoding; | |
var sb = new StringBuilder(); | |
for (var codePoint = 0; codePoint < 0x10ffff; codePoint++) | |
{ | |
var isSurrogateCodePoint = | |
codePoint <= UInt16.MaxValue | |
&& ( char.IsLowSurrogate((char) codePoint) | |
|| char.IsHighSurrogate((char) codePoint) | |
); | |
if (isSurrogateCodePoint) | |
continue; | |
var codePointString = char.ConvertFromUtf32(codePoint); | |
if (Regex.IsMatch(codePointString, @"\d")) | |
sb.AppendFormat("{0} ", codePointString); | |
} | |
Console.WriteLine(sb.ToString()); | |
Console.ReadKey(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment