本文整理汇总了C#中System.Char.IsControl方法的典型用法代码示例。如果您正苦于以下问题:C# Char.IsControl方法的具体用法?C# Char.IsControl怎么用?C# Char.IsControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Char
的用法示例。
在下文中一共展示了Char.IsControl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
public class ControlChars
{
public static void Main()
{
int charsWritten = 0;
for (int ctr = 0x00; ctr <= 0xFFFF; ctr++)
{
char ch = Convert.ToChar(ctr);
if (char.IsControl(ch))
{
Console.Write(@"\U{0:X4} ", ctr);
charsWritten++;
if (charsWritten % 6 == 0)
Console.WriteLine();
}
}
}
}
输出:
\U0000 \U0001 \U0002 \U0003 \U0004 \U0005 \U0006 \U0007 \U0008 \U0009 \U000A \U000B \U000C \U000D \U000E \U000F \U0010 \U0011 \U0012 \U0013 \U0014 \U0015 \U0016 \U0017 \U0018 \U0019 \U001A \U001B \U001C \U001D \U001E \U001F \U007F \U0080 \U0081 \U0082 \U0083 \U0084 \U0085 \U0086 \U0087 \U0088 \U0089 \U008A \U008B \U008C \U008D \U008E \U008F \U0090 \U0091 \U0092 \U0093 \U0094 \U0095 \U0096 \U0097 \U0098 \U0099 \U009A \U009B \U009C \U009D \U009E \U009F
示例2: Main
//引入命名空间
using System;
public class ControlChar
{
public static void Main()
{
string sentence = "This is a " + Environment.NewLine + "two-line sentence.";
for (int ctr = 0; ctr < sentence.Length; ctr++)
{
if (Char.IsControl(sentence, ctr))
Console.WriteLine("Control character \\U{0} found in position {1}.",
Convert.ToInt32(sentence[ctr]).ToString("X4"), ctr);
}
}
}
输出:
Control character \U000D found in position 10. Control character \U000A found in position 11.
示例3: Main
//引入命名空间
using System;
using System.Data;
using System.Text.RegularExpressions;
using System.Text;
class Class1{
static void Main(string[] args){
Console.WriteLine(GetCharKind('f'));
Console.WriteLine(GetCharKind('0'));
Console.WriteLine(GetCharKind('.'));
Console.WriteLine(GetCharKind('}'));
}
public static String GetCharKind(char theChar)
{
if (Char.IsControl(theChar))
{
return "Control";
}
else if (Char.IsDigit(theChar))
{
return "Digit";
}
else if (Char.IsLetter(theChar))
{
return "Letter";
}
else if (Char.IsNumber(theChar))
{
return "Number";
}
else if (Char.IsPunctuation(theChar))
{
return "Punctuation";
}
else if (Char.IsSeparator(theChar))
{
return "Separator";
}
else if (Char.IsSurrogate(theChar))
{
return "Surrogate";
}
else if (Char.IsSymbol(theChar))
{
return "Symbol";
}
else if (Char.IsWhiteSpace(theChar))
{
return "Whitespace";
}
else
{
return "Unknown";
}
}
}