ToChars() публичный статический Метод

public static ToChars ( int codePoint ) : char[]
codePoint int
Результат char[]
Пример #1
0
        /// <summary>
        /// Returns the index within this string of the first occurrence of the
        /// specified <paramref name="codePoint"/>.
        /// </summary>
        /// <param name="str">this string</param>
        /// <param name="codePoint">a codePoint representing a single character or surrogate pair</param>
        /// <returns>the index of the first occurrence of the character (or surrogate pair) in the string,
        /// or <c>-1</c> if the character (or surrogate pair) doesn't occur.</returns>
        public static int IndexOf(this string str, int codePoint)
        {
            if (codePoint >= 0 && codePoint < Character.MIN_SUPPLEMENTARY_CODE_POINT)
            {
                // handle most cases here (codePoint is a BMP code point)
                return(str.IndexOf((char)codePoint));
            }
            else if (codePoint >= Character.MIN_CODE_POINT && codePoint <= Character.MAX_CODE_POINT)
            {
                // codePoint is a surogate pair
                char[] pair = Character.ToChars(codePoint);
                char   hi   = pair[0];
                char   lo   = pair[1];
                for (int i = 0; i < str.Length - 1; i++)
                {
                    if (str[i] == hi && str[i + 1] == lo)
                    {
                        return(i);
                    }
                }
            }

            // codePoint is negative or not found in string
            return(-1);
        }
Пример #2
0
 /// <summary>
 /// Appends the string representation of the <paramref name="codePoint"/>
 /// argument to this sequence.
 ///
 /// <para>
 /// The argument is appended to the contents of this sequence.
 /// The length of this sequence increases by <see cref="Character.CharCount(int)"/>.
 /// </para>
 /// <para>
 /// The overall effect is exactly as if the argument were
 /// converted to a <see cref="char"/> array by the method
 /// <see cref="Character.ToChars(int)"/> and the character in that array
 /// were then <see cref="StringBuilder.Append(char[])">appended</see> to this
 /// <see cref="StringBuilder"/>.
 /// </para>
 /// </summary>
 /// <param name="text">This <see cref="StringBuilder"/>.</param>
 /// <param name="codePoint">a Unicode code point</param>
 /// <returns>a reference to this object.</returns>
 public static StringBuilder AppendCodePoint(this StringBuilder text, int codePoint)
 {
     text.Append(Character.ToChars(codePoint));
     return(text);
 }