String - IsLetterOrDigit
Indicates whether the character at the specified position in a specified string is categorized as a letter or a decimal digit.
public static void Main() { string input = ".NET 4.7.2"; Console.WriteLine("Is each of the following characters a letter or digit?"); for (int i = 0; i < input.Length; i++) { // C# Extension Method: String - IsLetterOrDigit var result = input.IsLetterOrDigit(i); Console.WriteLine("input[{0}] = {1} ", i, result); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Indicates whether the character at the specified position in a specified string is categorized as a letter or /// a decimal digit. /// </summary> /// <param name="s">A string.</param> /// <param name="index">The position of the character to evaluate in .</param> /// <returns>true if the character at position in is a letter or a decimal digit; otherwise, false.</returns> public static Boolean IsLetterOrDigit(this String s, Int32 index) { return Char.IsLetterOrDigit(s, index); } }