Char - IsSurrogate
Indicates whether the specified character has a surrogate code unit.
public static void Main() { char [] input = new char[] { 'a', '\uD800', '\uDC00', 'z' }; Console.WriteLine("Is each of the following characters a high surrogate?"); for (int i = 0; i < input.Length; i++) { // C# Extension Method: Char - IsSurrogate var result = input[i].IsSurrogate(); Console.WriteLine("input[{0}] = {1} ", i, result); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Indicates whether the specified character has a surrogate code unit. /// </summary> /// <param name="c">The Unicode character to evaluate.</param> /// <returns>true if is either a high surrogate or a low surrogate; otherwise, false.</returns> public static Boolean IsSurrogate(this Char c) { return Char.IsSurrogate(c); } }