C# Char ConvertToUtf32(String, Int32)

Description

Char ConvertToUtf32(String, Int32) converts the value of a UTF-16 encoded character or surrogate pair at a specified position in a string into a Unicode code point.

Syntax

Char.ConvertToUtf32(String, Int32) has the following syntax.


public static int ConvertToUtf32(
  string s,
  int index
)

Parameters

Char.ConvertToUtf32(String, Int32) has the following parameters.

  • s - A string that contains a character or surrogate pair.
  • index - The index position of the character or surrogate pair in s.

Returns

Char.ConvertToUtf32(String, Int32) method returns The 21-bit Unicode code point represented by the character or surrogate pair at the position in the s parameter specified by the index parameter.

Example

The following code example demonstrates the ConvertToUtf32.


/*w  w w  . j  a v a 2s .c om*/

using System;

class Sample 
{
    public static void Main() 
    {
        int letterA = 0x0041;  //U+00041 = LATIN CAPITAL LETTER A 
        int music   = 0x1D161; //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE 
        string s1 = "";
        
        Console.WriteLine("Create a code point from a UTF-16 encoded string.");
        letterA = Char.ConvertToUtf32(s1, 0);
        Console.Write("    1b) ");
        Show(s1);
        Console.WriteLine(" => 0x{0:X}", letterA);
    }

    private static void Show(string s)
    {
    for (int x = 0; x < s.Length; x++)
        {
        Console.Write("0x{0:X}{1}", 
                       (int)s[x], 
                       ((x == s.Length-1)? String.Empty : ", "));
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version