How do I get a list of all the printable characters in C#?

后端 未结 5 749
我寻月下人不归
我寻月下人不归 2020-12-18 19:10

I\'d like to be able to get a char array of all the printable characters in C#, does anybody know how to do this?

edit:

By printable I mean

5条回答
  •  旧巷少年郎
    2020-12-18 19:52

    This will give you a list with all characters that are not considered control characters:

    List printableChars = new List();
    for (int i = char.MinValue; i <= char.MaxValue; i++)
    {
        char c = Convert.ToChar(i);
        if (!char.IsControl(c))
        {
            printableChars.Add(c);
        }
    }
    

    You may want to investigate the other Char.IsXxxx methods to find a combination that suits your requirements.

提交回复
热议问题