วิธี Char.IsControl(String, Int32) ใน C# ใช้เพื่อระบุว่าอักขระที่ตำแหน่งที่ระบุในสตริงที่ระบุถูกจัดประเภทเป็นอักขระควบคุมหรือไม่
ไวยากรณ์
public static bool IsControl (string str, int index);
ด้านบน str คือสตริง พารามิเตอร์ดัชนีคือตำแหน่งของอักขระที่จะประเมินใน 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