在 C# 中的 Char.IsControl(String, Int32) 方法
C# 中的 Char.IsControl(String, Int32) 方法用於指示指定字串中指定位置處的字元是否被歸類為控制字元。
語法
public static bool IsControl (string str, int index);
上面,str 是一個字串。index 引數是要在 str 中評估的字元的位置。
現在讓我們看一個示例來實現 Char.IsControl(String, Int32) 方法 -
示例
using System; using System.Globalization; public class Demo { public static void Main(){ string val = "hjk9878hj"; Console.WriteLine("String = "+val); UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4); Console.WriteLine("The value at specific index = "+unicode); bool res = Char.IsControl(val, 4); if (res) Console.WriteLine("Control character found!"); else Console.WriteLine("Control character isn't there"); } }
輸出
將產生以下輸出 -
String = hjk9878hj The value at specific index = DecimalDigitNumber Control character isn't there
廣告