Char.ConvertFromUtf32 メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Char.ConvertFromUtf32 メソッドの意味・解説 

Char.ConvertFromUtf32 メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定されUnicode コード ポイントUTF-16 エンコード文字列変換します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

utf32 が、U+0 から U+10FFFF (サロゲート ペア場合U+D800 から U+DFFF) の範囲内の、有効な 21 ビット Unicode コード ポイントではありません。

解説解説
使用例使用例

ConvertToUtf32 メソッドおよび ConvertFromUtf32 メソッドコード例次に示します

' This example demonstrates the Char.ConvertFromUtf32() method
'                           and Char.ConvertToUtf32() overloads.
Imports System
Imports Microsoft.VisualBasic

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
 character."
      
      '  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 'Main
   
   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 x
   End Sub 'Show
End Class 'Sample
'
'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 character.
'    2c) 0xD834, 0xDD61 => 0x1D161
'
// 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 character.";

//  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 character.
    2c) 0xD834, 0xDD61 => 0x1D161

*/
// This example demonstrates the Char.ConvertFromUtf32() method
//                           and Char.ConvertToUtf32() overloads.
using namespace System;
void Show( String^ s )
{
//   Console::Write( "0x{0:X}, 0x{1:X}", (int)s->get_Chars(
 0 ), (int)s->get_Chars( 1 ) );
   Console::Write( "0x{0:X}, 0x{1:X}", (int)s[ 0 ],
 (int)s[ 1 ] );
}

int main()
{
   int music = 0x1D161; //U+1D161 = MUSICAL SYMBOL
 SIXTEENTH NOTE

   String^ s1;
   String^ comment1a = "Create a UTF-16 encoded string from
 a code point.";
   String^ comment1b = "Create a code point from a surrogate pair at a certain position in
 a string.";
   String^ comment1c = "Create a code point from a high surrogate and a low
 surrogate character.";
   
   // -------------------------------------------------------------------
   //  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( comment1a );
   s1 = Char::ConvertFromUtf32( music );
   Console::Write( "    1a) 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( comment1b );
   music = Char::ConvertToUtf32( s1, 0 );
   Console::Write( "    1b) " );
   Show( s1 );
   Console::WriteLine( " => 0x{0:X}", music );
   
   //  Convert the high and low characters in the surrogate pair into a
 code point.
   Console::WriteLine( comment1c );
   music = Char::ConvertToUtf32( s1[ 0 ], s1[ 1 ] );
   Console::Write( "    1c) " );
   Show( s1 );
   Console::WriteLine( " => 0x{0:X}", music );
}

/*
This example produces the following results:

Create a UTF-16 encoded string from a code point.
    1a) 0x1D161 => 0xD834, 0xDD61
Create a code point from a surrogate pair at a certain position in
 a string.
    1b) 0xD834, 0xDD61 => 0x1D161
Create a code point from a high surrogate and a low surrogate character.
    1c) 0xD834, 0xDD61 => 0x1D161

*/
// This example demonstrates the Char.ConvertFromUtf32() method
// and Char.ConvertToUtf32() overloads.
import System.*;

class Sample
{
    public static void main(String[]
 args)
    {
        int letterA = 0x41; //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 character.";
        //  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} => ", (Int32)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}", (Int32)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} => ", (Int32)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}", (Int32)music);
        //  Convert the high and low characters in the surrogate pair
 into a
        //  code point.
        Console.WriteLine(comment2C);
        music = Char.ConvertToUtf32(s1.get_Chars(0), s1.get_Chars(1));
        Console.Write("    2c) ");
        Show(s1);
        Console.WriteLine(" => 0x{0:X}", (Int32)music);
    } //main

    private static void
 Show(String s)
    {
        for (int x = 0; x < s.get_Length();
 x++) {
            Console.Write("0x{0:X}{1}", (Int32)(s.get_Chars(x)),
                (x == s.get_Length() - 1) ? "" : ", ");
        }
    } //Show
} //Sample

/*
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 character.
    2c) 0xD834, 0xDD61 => 0x1D161

*/
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Char 構造体
Char メンバ
System 名前空間
ConvertToUtf32
System.Text.UTF32Encoding



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

Char.ConvertFromUtf32 メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Char.ConvertFromUtf32 メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS