CSharp examples for System:Char
Validates the char is 0-9, A-F or a-f
using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w w w . j a va 2s . com public class Main{ /// <summary> /// Validates the char is 0-9, A-F or a-f /// </summary> public static bool IsHex(this char c) { if (char.IsDigit(c)) { return true; } return char.ToUpperInvariant(c) >= 'A' && char.ToUpperInvariant(c) <= 'F'; } /// <summary> /// Validates all chars are 0-9, A-F or a-f /// </summary> public static bool IsHex(this string str) { if (string.IsNullOrWhiteSpace(str)) { return false; } return str.All(IsHex); } }