Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Phương thức Uri.IsHexEncoding() trong C#

Phương thức Uri.IsHexEncoding() trong C# xác định xem một ký tự trong chuỗi có được mã hóa hexadecimal hay không.

Cú pháp

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

Tham số pattern là chuỗi cần kiểm tra, index là vị trí trong pattern để kiểm tra mã hóa hexadecimal.

Ví dụ

using System; 
public class Demo { 
    public static void Main(){ 
        string pattern = "%50"; 
        bool res = Uri.IsHexEncoding(pattern, 0); 
        if (res) 
            Console.WriteLine("Hợp lệ: Đã mã hóa Hexadecimal"); 
        else 
            Console.WriteLine("Không hợp lệ: Đã mã hóa Hexadecimal"); 
    } 
}

Kết quả

Hợp lệ: Đã mã hóa Hexadecimal

Ví dụ khác

using System; 
public class Demo { 
    public static void Main(){ 
        string pattern = "%60"; 
        bool res = Uri.IsHexEncoding(pattern, 1); 
        if (res) 
            Console.WriteLine("Hợp lệ: Đã mã hóa Hexadecimal"); 
        else 
            Console.WriteLine("Không hợp lệ: Đã mã hóa Hexadecimal"); 
    } 
}

Kết quả

Không hợp lệ: Đã mã hóa Hexadecimal