当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Uri.IsHexEncoding()用法及代码示例


Uri.IsHexEncoding(String,Int32)方法用于检查字符串中的字符是否用十六进制编码。这将检查字符串中遵循模式“%hexhex”的十六进制编码,其中“hex”是从0到9的数字或A-F(大小写敏感)的字母。

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

参数:
pattern:这是要检查的字符串。
index:这是样式中检查十六进制编码的位置。


返回值:如果模式在指定位置以十六进制编码,则此方法返回一个布尔值,该值为true,否则为false。

以下示例程序旨在说明Uri.IsHexEncoding(String,Int32)方法的用法:

示例1:

// C# program to demonstrate the 
// Uri.IsHexEncoding(String, 
// Int32)  Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // Declaring and initializing pattern 
        string pattern = "%75"; 
  
        // Declaring and initializing index 
        int index = 1; 
  
        // Validating the Character in the String 
        // using IsHexEncoding(String, Int32)  method 
        bool value = Uri.IsHexEncoding(pattern, index); 
  
        // Displaying the result 
        if (value) 
            Console.WriteLine("{0}({1}) is a valid "+ 
                     "Hexadecimal Encoded", pattern); 
        else
            Console.WriteLine("{0} is a valid"+ 
              " Hexadecimal Encoded", pattern); 
    } 
}
输出:
%75 is a valid Hexadecimal Encoded

示例2:

// C# program to demonstrate the 
// Uri.IsHexEncoding(String,  
// Int32) Method 
using System; 
using System.Globalization; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // calling get() method 
        get("%65", 1); 
        get("%75", 0); 
        get("%55", 0); 
    } 
  
    // defining get() method 
    public static void get(string pattern,  
                                int index) 
    { 
  
        // Validating the Character in the String 
        // using IsHexEncoding(String, Int32)  method 
        bool value = Uri.IsHexEncoding(pattern, index); 
  
        // Displaying the result 
        if (value) 
            Console.WriteLine("{0} is a valid"+ 
              " Hexadecimal Encoded", pattern); 
        else
            Console.WriteLine("{0} is a not valid"+ 
                  " Hexadecimal Encoded", pattern); 
    } 
}
输出:
%65 is a not valid Hexadecimal Encoded
%75 is a valid Hexadecimal Encoded
%55 is a valid Hexadecimal Encoded

参考:



相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 C# | Uri.IsHexEncoding() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。