要检查指定的Unicode字符是否为标点符号,代码如下-
using System; public class Demo { public static void Main() { bool res; char val = 'q'; Console.WriteLine("Value = "+val); res = Char.IsPunctuation(val); Console.WriteLine("Is the value a punctuation? = "+res); } }
输出结果
这将产生以下输出-
Value = q Is the value a punctuation? = False
让我们看另一个例子-
using System; public class Demo { public static void Main() { bool res; char val = ','; Console.WriteLine("Value = "+val); res = Char.IsPunctuation(val); Console.WriteLine("Is the value a punctuation? = "+res); } }
输出结果
这将产生以下输出-
Value = , Is the value a punctuation? = True