String - IsSurrogate
Indicates whether the character at the specified position in a specified string has a surrogate code unit.
public static void Main() { string input = new String(new char[] { 'a', '\uD800', '\uDC00', 'z' }); Console.WriteLine("Is each of the following characters a low surrogate?"); for (int i = 0; i < input.Length; i++) { // C# Extension Method: String - IsSurrogate var result = input.IsSurrogate(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 has a surrogate code unit. /// </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 either a high surrogate or a low surrogate; otherwise, false. /// </returns> public static Boolean IsSurrogate(this String s, Int32 index) { return Char.IsSurrogate(s, index); } }