Char.ConvertToUtf32 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
UTF-16으로 인코딩된 서로게이트 쌍의 값을 유니코드 코드 포인트로 변환합니다.
오버로드
| Name | Description |
|---|---|
| ConvertToUtf32(Char, Char) |
UTF-16으로 인코딩된 서로게이트 쌍의 값을 유니코드 코드 포인트로 변환합니다. |
| ConvertToUtf32(String, Int32) |
문자열의 지정된 위치에 있는 UTF-16으로 인코딩된 문자 또는 서로게이트 쌍의 값을 유니코드 코드 포인트로 변환합니다. |
예제
다음 코드 예제에서는 및 ConvertToUtf32 메서드를 ConvertFromUtf32 보여 줍니다.
// This example demonstrates the Char.ConvertFromUtf32() method
// and Char.ConvertToUtf32() overloads.
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;
string comment = "Create a UTF-16 encoded string from a code point.";
string comment1b = "Create a code point from a UTF-16 encoded string.";
string comment2b = "Create a code point from a surrogate pair at a certain position in a string.";
string comment2c = "Create a code point from a high surrogate and a low surrogate code point.";
// Convert code point U+0041 to UTF-16. The UTF-16 equivalent of
// U+0041 is a Char with hexadecimal value 0041.
Console.WriteLine(comment);
s1 = Char.ConvertFromUtf32(letterA);
Console.Write(" 1a) 0x{0:X} => ", letterA);
Show(s1);
Console.WriteLine();
// Convert the lone UTF-16 character to a code point.
Console.WriteLine(comment1b);
letterA = Char.ConvertToUtf32(s1, 0);
Console.Write(" 1b) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", letterA);
Console.WriteLine();
// -------------------------------------------------------------------
// Convert the code point U+1D161 to UTF-16. The UTF-16 equivalent of
// U+1D161 is a surrogate pair with hexadecimal values D834 and DD61.
Console.WriteLine(comment);
s1 = Char.ConvertFromUtf32(music);
Console.Write(" 2a) 0x{0:X} => ", music);
Show(s1);
Console.WriteLine();
// Convert the surrogate pair in the string at index position
// zero to a code point.
Console.WriteLine(comment2b);
music = Char.ConvertToUtf32(s1, 0);
Console.Write(" 2b) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", music);
// Convert the high and low characters in the surrogate pair into a code point.
Console.WriteLine(comment2c);
music = Char.ConvertToUtf32(s1[0], s1[1]);
Console.Write(" 2c) ");
Show(s1);
Console.WriteLine(" => 0x{0:X}", music);
}
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 : ", "));
}
}
}
/*
This example produces the following results:
Create a UTF-16 encoded string from a code point.
1a) 0x41 => 0x41
Create a code point from a UTF-16 encoded string.
1b) 0x41 => 0x41
Create a UTF-16 encoded string from a code point.
2a) 0x1D161 => 0xD834, 0xDD61
Create a code point from a surrogate pair at a certain position in a string.
2b) 0xD834, 0xDD61 => 0x1D161
Create a code point from a high surrogate and a low surrogate code point.
2c) 0xD834, 0xDD61 => 0x1D161
*/
open System
let show (s: string) =
for x = 0 to s.Length - 1 do
printf $"""0x{int s[x]:X}{if x = s.Length - 1 then String.Empty else ", "}"""
[<EntryPoint>]
let main _ =
let letterA = 0x0041 //U+00041 = LATIN CAPITAL LETTER A
let music = 0x1D161 //U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
let comment = "Create a UTF-16 encoded string from a code point."
let comment1b = "Create a code point from a UTF-16 encoded string."
let comment2b = "Create a code point from a surrogate pair at a certain position in a string."
let comment2c = "Create a code point from a high surrogate and a low surrogate code point."
// Convert code point U+0041 to UTF-16. The UTF-16 equivalent of
// U+0041 is a Char with hexadecimal value 0041.
printfn $"{comment}"
let s1 = Char.ConvertFromUtf32 letterA
printf $" 1a) 0x{letterA:X} => "
show s1
printfn ""
// Convert the lone UTF-16 character to a code point.
printfn $"{comment1b}"
let letterA = Char.ConvertToUtf32(s1, 0)
printf " 1b) "
show s1
printfn $" => 0x{letterA:X}"
printfn ""
// -------------------------------------------------------------------
// Convert the code point U+1D161 to UTF-16. The UTF-16 equivalent of
// U+1D161 is a surrogate pair with hexadecimal values D834 and DD61.
printfn $"{comment}"
let s1 = Char.ConvertFromUtf32 music
printf $" 2a) 0x{music:X} => "
show s1
printfn ""
// Convert the surrogate pair in the string at index position
// zero to a code point.
printfn $"{comment2b}"
let music = Char.ConvertToUtf32(s1, 0)
printf " 2b) "
show s1
printfn $" => 0x{music:X}"
// Convert the high and low characters in the surrogate pair into a code point.
printfn $"{comment2c}"
let music = Char.ConvertToUtf32(s1[0], s1[1])
printf " 2c) "
show s1
printfn $" => 0x{music:X}"
0
// This example produces the following results:
//
// Create a UTF-16 encoded string from a code point.
// 1a) 0x41 => 0x41
// Create a code point from a UTF-16 encoded string.
// 1b) 0x41 => 0x41
//
// Create a UTF-16 encoded string from a code point.
// 2a) 0x1D161 => 0xD834, 0xDD61
// Create a code point from a surrogate pair at a certain position in a string.
// 2b) 0xD834, 0xDD61 => 0x1D161
// Create a code point from a high surrogate and a low surrogate code point.
// 2c) 0xD834, 0xDD61 => 0x1D161
Class Sample
Public Shared Sub Main()
Dim letterA As Integer = &H41 'U+00041 = LATIN CAPITAL LETTER A
Dim music As Integer = &H1D161 'U+1D161 = MUSICAL SYMBOL SIXTEENTH NOTE
Dim s1 As String
Dim comment As String = "Create a UTF-16 encoded string from a code point."
Dim comment1b As String = "Create a code point from a UTF-16 encoded string."
Dim comment2b As String = "Create a code point from a surrogate pair at a certain position in a string."
Dim comment2c As String = "Create a code point from a high surrogate and a low surrogate code point."
' Convert code point U+0041 to UTF-16. The UTF-16 equivalent of
' U+0041 is a Char with hexadecimal value 0041.
Console.WriteLine(comment)
s1 = [Char].ConvertFromUtf32(letterA)
Console.Write(" 1a) 0x{0:X} => ", letterA)
Show(s1)
Console.WriteLine()
' Convert the lone UTF-16 character to a code point.
Console.WriteLine(comment1b)
letterA = [Char].ConvertToUtf32(s1, 0)
Console.Write(" 1b) ")
Show(s1)
Console.WriteLine(" => 0x{0:X}", letterA)
Console.WriteLine()
' -------------------------------------------------------------------
' Convert the code point U+1D161 to UTF-16. The UTF-16 equivalent of
' U+1D161 is a surrogate pair with hexadecimal values D834 and DD61.
Console.WriteLine(comment)
s1 = [Char].ConvertFromUtf32(music)
Console.Write(" 2a) 0x{0:X} => ", music)
Show(s1)
Console.WriteLine()
' Convert the surrogate pair in the string at index position
' zero to a code point.
Console.WriteLine(comment2b)
music = [Char].ConvertToUtf32(s1, 0)
Console.Write(" 2b) ")
Show(s1)
Console.WriteLine(" => 0x{0:X}", music)
' Convert the high and low characters in the surrogate pair into a code point.
Console.WriteLine(comment2c)
music = [Char].ConvertToUtf32(s1.Chars(0), s1.Chars(1))
Console.Write(" 2c) ")
Show(s1)
Console.WriteLine(" => 0x{0:X}", music)
End Sub
Private Shared Sub Show(s As String)
Dim x As Integer
If s.Length = 0 Then Exit Sub
For x = 0 To s.Length - 1
Console.Write("0x{0:X}{1}", _
AscW(s.Chars(x)), _
IIf(x = s.Length - 1, [String].Empty, ", "))
Next
End Sub
End Class
'
'This example produces the following results:
'
'Create a UTF-16 encoded string from a code point.
' 1a) 0x41 => 0x41
'Create a code point from a UTF-16 encoded string.
' 1b) 0x41 => 0x41
'
'Create a UTF-16 encoded string from a code point.
' 2a) 0x1D161 => 0xD834, 0xDD61
'Create a code point from a surrogate pair at a certain position in a string.
' 2b) 0xD834, 0xDD61 => 0x1D161
'Create a code point from a high surrogate and a low surrogate code point.
' 2c) 0xD834, 0xDD61 => 0x1D161
'
ConvertToUtf32(Char, Char)
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
UTF-16으로 인코딩된 서로게이트 쌍의 값을 유니코드 코드 포인트로 변환합니다.
public:
static int ConvertToUtf32(char highSurrogate, char lowSurrogate);
public static int ConvertToUtf32(char highSurrogate, char lowSurrogate);
static member ConvertToUtf32 : char * char -> int
Public Shared Function ConvertToUtf32 (highSurrogate As Char, lowSurrogate As Char) As Integer
매개 변수
- highSurrogate
- Char
상위 서로게이트 코드 단위(즉, U+D800부터 U+DBFF까지의 코드 단위)입니다.
- lowSurrogate
- Char
낮은 서로게이트 코드 단위(즉, U+DC00부터 U+DFFF까지의 코드 단위)입니다.
반품
및 highSurrogate 매개 변수가 나타내는 lowSurrogate 21비트 유니코드 코드 포인트입니다.
예외
highSurrogate 은 U+D800~U+DBFF lowSurrogate 범위에 없거나 U+DC00~U+DFFF 범위에 있지 않습니다.
설명
이 메서드를 사용하여 서로게이트 쌍을 21비트 유니코드 코드 포인트로 변환합니다. UTF-16 데이터를 UTF-32 데이터로 변환하려면 클래스를 System.Text.UTF32Encoding 사용합니다.
일반적으로 UTF-16 인코딩은 단일 유니코드 문자를 16비트 코드 단위로 나타냅니다. 그러나 단일 추상 문자를 두 개의 16비트 코드 단위로 나타낼 수 있는 서로게이트 쌍도 지원합니다. 이러한 두 Char 개체에는 첫 번째(높음) 서로게이트의 경우 U+D800에서 U+DBFF까지의 코드 단위와 두 번째(낮음) 서로게이트의 경우 U+DC00에서 U+DFFF까지의 코드 단위가 있어야 합니다. 서로게이트 쌍은 UTF-16 인코딩에서만 지원됩니다. 이 메서드를 사용하면 UTF-16 서로게이트 쌍으로 표현된 문자를 UTF-32 인코딩을 사용하여 문자로 변환할 수 있습니다.
추가 정보
적용 대상
ConvertToUtf32(String, Int32)
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
- Source:
- Char.cs
문자열의 지정된 위치에 있는 UTF-16으로 인코딩된 문자 또는 서로게이트 쌍의 값을 유니코드 코드 포인트로 변환합니다.
public:
static int ConvertToUtf32(System::String ^ s, int index);
public static int ConvertToUtf32(string s, int index);
static member ConvertToUtf32 : string * int -> int
Public Shared Function ConvertToUtf32 (s As String, index As Integer) As Integer
매개 변수
- s
- String
문자 또는 서로게이트 쌍을 포함하는 문자열입니다.
- index
- Int32
에 있는 문자 또는 서로게이트 쌍의 인덱스 s위치입니다.
반품
매개 변수로 지정된 매개 변수의 위치에 s 있는 문자 또는 서로게이트 쌍으로 표현되는 index 21비트 유니코드 코드 포인트입니다.
예외
s은 null입니다.
index가 내의 위치가 아닌 경우 s
지정된 인덱스 위치에는 서로게이트 쌍이 포함되며 쌍의 첫 번째 문자가 유효한 상위 서로게이트가 아니거나 쌍의 두 번째 문자가 유효한 하위 서로게이트가 아닙니다.
설명
이 메서드를 사용하여 문자 또는 서로게이트 쌍을 21비트 유니코드 코드 포인트로 변환합니다. UTF-16 데이터를 UTF-32 데이터로 변환하려면 클래스를 System.Text.UTF32Encoding 사용합니다.