String - IsSurrogatePair
Indicates whether two adjacent objects at a specified position in a string form a surrogate pair.
public static void Main() { string input = new String(new char[] { 'a', '\uD800', '\uDC00', 'z' }); Console.WriteLine("Is each of the following characters a surrogate pair?"); for (int i = 0; i < input.Length; i++) { // C# Extension Method: String - IsSurrogatePair var result = input.IsSurrogatePair(i); Console.WriteLine("input[{0}] = {1} ", i, result); } }
View Source
using System; public static partial class Extensions { /// <summary> /// Indicates whether two adjacent objects at a specified position in a string form a surrogate pair. /// </summary> /// <param name="s">A string.</param> /// <param name="index">The starting position of the pair of characters to evaluate within .</param> /// <returns> /// true if the parameter includes adjacent characters at positions and + 1, and the numeric value of the /// character at position ranges from U+D800 through U+DBFF, and the numeric value of the character at position /// +1 ranges from U+DC00 through U+DFFF; otherwise, false. /// </returns> public static Boolean IsSurrogatePair(this String s, Int32 index) { return Char.IsSurrogatePair(s, index); } }