Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

เมธอด Uri.IsHexEncoding() ใน C#


เมธอด Uri.IsHexEncoding() ใน C# ใช้กำหนดว่าอักขระในสตริงเป็นการเข้ารหัสฐานสิบหกหรือไม่

ไวยากรณ์

public static bool IsHexEncoding (string pattern, int index);

พารามิเตอร์ pattern คือสตริงที่ต้องการตรวจสอบ ส่วน index คือตำแหน่งใน pattern ที่ต้องการตรวจสอบการเข้ารหัสฐานสิบหก

ตัวอย่าง

using System; 
public class Demo { 
    public static void Main(){ 
        string pattern = "%50"; 
        bool res = Uri.IsHexEncoding(pattern, 0); 
        if (res) 
            Console.WriteLine("Valid: Hexadecimal Encoded"); 
        else 
            Console.WriteLine("Invalid: Hexadecimal Encoded"); 
    } 
}

ผลลัพธ์

Valid: Hexadecimal Encoded

ตัวอย่างที่ 2

using System; 
public class Demo { 
    public static void Main(){ 
        string pattern = "%60"; 
        bool res = Uri.IsHexEncoding(pattern, 1); 
        if (res) 
            Console.WriteLine("Valid: Hexadecimal Encoded"); 
        else 
            Console.WriteLine("Invalid: Hexadecimal Encoded"); 
    } 
}

ผลลัพธ์

Invalid: Hexadecimal Encoded