UTF8Encoding コンストラクタ ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > UTF8Encoding コンストラクタ ()の意味・解説 

UTF8Encoding コンストラクタ ()

UTF8Encoding クラス新しインスタンス初期化します。

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

public UTF8Encoding ()
public:
UTF8Encoding ()
public UTF8Encoding ()
public function UTF8Encoding ()
解説解説
使用例使用例

次のコード例は、新しUTF8Encoding インスタンス作成してエンコード名を表示する方法示してます。

Imports System
Imports System.Text

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim utf8 As New
 UTF8Encoding()
        Dim encodingName As String
 = utf8.EncodingName
        Console.WriteLine("Encoding name: " &
 encodingName)
    End Sub 'Main
End Class 'UTF8EncodingExample
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main()
 {
        UTF8Encoding utf8 = new UTF8Encoding();
        String encodingName = utf8.EncodingName;
        Console.WriteLine("Encoding name: " + encodingName);
    }
}
using namespace System;
using namespace System::Text;
int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   String^ encodingName = utf8->EncodingName;
   Console::WriteLine( "Encoding name: {0}", encodingName );
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[]
 args)
    {
        UTF8Encoding utf8 = new UTF8Encoding();
        String encodingName = utf8.get_EncodingName();
        Console.WriteLine(("Encoding name: " + encodingName));
    } //main
} //UTF8EncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UTF8Encoding クラス
UTF8Encoding メンバ
System.Text 名前空間
GetPreamble

UTF8Encoding コンストラクタ (Boolean, Boolean)

UTF8Encoding クラス新しインスタンス初期化します。パラメータでは、Unicode バイト順マーク付加するかどうか、および無効なエンコーディング検出されたときに例外スローするかどうか指定します

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

Public Sub New ( _
    encoderShouldEmitUTF8Identifier As Boolean,
 _
    throwOnInvalidBytes As Boolean _
)
Dim encoderShouldEmitUTF8Identifier As Boolean
Dim throwOnInvalidBytes As Boolean

Dim instance As New UTF8Encoding(encoderShouldEmitUTF8Identifier,
 throwOnInvalidBytes)
public UTF8Encoding (
    bool encoderShouldEmitUTF8Identifier,
    bool throwOnInvalidBytes
)
public:
UTF8Encoding (
    bool encoderShouldEmitUTF8Identifier, 
    bool throwOnInvalidBytes
)
public UTF8Encoding (
    boolean encoderShouldEmitUTF8Identifier, 
    boolean throwOnInvalidBytes
)
public function UTF8Encoding (
    encoderShouldEmitUTF8Identifier : boolean, 
    throwOnInvalidBytes : boolean
)

パラメータ

encoderShouldEmitUTF8Identifier

Unicode バイト順マーク付加するよう指定する場合trueそれ以外場合false

throwOnInvalidBytes

無効なエンコーディング検出され場合に、例外スローすることを指定する場合trueそれ以外場合false

解説解説
使用例使用例

次の例は、エンコーディング時に Unicode バイト順マーク プリフィックス作成せず、無効なエンコーディング検出され場合には例外スローするよう指定して新しUTF8Encoding インスタンス作成する方法示してます。このコンストラクタ動作を、無効なエンコーディング検出され場合でも例外スローしない UTF8Encoding既定コンストラクタ比較してください

Imports System
Imports System.Text
Imports Microsoft.VisualBasic
'Imports Microsoft.VisualBasic.Strings

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim utf8 As New
 UTF8Encoding()
        Dim utf8ThrowException As New
 UTF8Encoding(False, True)
        
        ' This array contains two high surrogates in a row:
        ' ChrW(55297) and ChrW(55298).
        ' A high surrogate should be followed by a low surrogate.
        Dim chars() As Char
 = {"a"c, "b"c, "c"c,
 ChrW(55297), ChrW(55298), "d"c}
        
        ' The following method call will not throw an exception.
        Dim bytes As Byte()
 = utf8.GetBytes(chars)
        ShowArray(bytes)
        
        Try
            ' The following method call will throw an exception.
            bytes = utf8ThrowException.GetBytes(chars)
        Catch e As Exception
            Console.WriteLine("Exception raised. "
 + ControlChars.Cr + "Message: {0}", e.Message)
        End Try
    End Sub
    
    
    Public Shared Sub ShowArray(theArray
 As Array)
        Dim o As Object
        For Each o In  theArray
            Console.Write("[{0}]", o)
        Next o
        Console.WriteLine()
    End Sub
End Class
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main()
 {
        UTF8Encoding utf8 = new UTF8Encoding();
        UTF8Encoding utf8ThrowException = new UTF8Encoding(false,
 true);

        // This array contains two high surrogates in a row (\uD801,
 \uD802).
        // A high surrogate should be followed by a low surrogate.
        Char[] chars = new Char[] {'a', 'b', 'c', '\uD801', '\uD802',
 'd'};

        // The following method call will not throw an exception.
        Byte[] bytes = utf8.GetBytes(chars);
        ShowArray(bytes);

        try {
            // The following method call will throw an exception.
            bytes = utf8ThrowException.GetBytes(chars);
        } catch (Exception e) {
            Console.WriteLine("Exception raised. \nMessage: {0}", e.Message);
        }
    }

    public static void ShowArray(Array
 theArray) {
        foreach (Object o in theArray) {
            Console.Write("[{0}]", o);
        }
        Console.WriteLine();
    }
}
using namespace System;
using namespace System::Text;
using namespace System::Collections;
void ShowArray( Array^ theArray )
{
   IEnumerator^ myEnum = theArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ o = safe_cast<Object^>(myEnum->Current);
      Console::Write( "[{0}]", o );
   }

   Console::WriteLine();
}

int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   UTF8Encoding^ utf8ThrowException = gcnew UTF8Encoding( false,true
 );
   
   // This array contains two high surrogates in a row (\uD801, \uD802).
   // A high surrogate should be followed by a low surrogate.
   array<Char>^chars = {'a','b','c',L'\xD801',L'\xD802','d'};
   
   // The following method call will not throw an exception.
   array<Byte>^bytes = utf8->GetBytes( chars );
   ShowArray( bytes );
   try
   {
      
      // The following method call will throw an exception.
      bytes = utf8ThrowException->GetBytes( chars );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception raised. \nMessage: {0}", e->Message
 );
   }

}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[]
 args)
    {
        UTF8Encoding utf8 =  new UTF8Encoding();
        UTF8Encoding utf8ThrowException =  new UTF8Encoding(false,
 true);
      
        // This array contains two high surrogates in a row (\uD801,
 \uD802).
        // A high surrogate should be followed by a low surrogate.
        char chars[] = new char[]
 { 'a', 'b', 'c', '\uD801', '\uD802', 'd' };
   
        // The following method call will not throw an exception.
        ubyte bytes[] = utf8.GetBytes(chars);
           ShowArray(bytes);
        try {
             // The following method call will throw an exception.
            bytes = utf8ThrowException.GetBytes(chars);
        }
        catch(System.Exception  e) {
            Console.WriteLine("Exception raised. \nMessage: {0}", 
            e.get_Message());
        } 
    } //main
   
    public static void ShowArray(Array
 theArray) 
    {
        Object o = null;        
        for (int iCtr=0; iCtr < theArray.get_Count();
 iCtr++) {
            o = theArray.get_Item(iCtr);
            Console.Write("[{0}]", o);
        }
        Console.WriteLine();
    } //ShowArray
} //UTF8EncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UTF8Encoding クラス
UTF8Encoding メンバ
System.Text 名前空間
GetPreamble

UTF8Encoding コンストラクタ (Boolean)

UTF8Encoding クラス新しインスタンス初期化します。パラメータでは、Unicode バイト順マーク付加するかどうか指定します

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

Public Sub New ( _
    encoderShouldEmitUTF8Identifier As Boolean
 _
)
Dim encoderShouldEmitUTF8Identifier As Boolean

Dim instance As New UTF8Encoding(encoderShouldEmitUTF8Identifier)
public UTF8Encoding (
    bool encoderShouldEmitUTF8Identifier
)
public:
UTF8Encoding (
    bool encoderShouldEmitUTF8Identifier
)
public UTF8Encoding (
    boolean encoderShouldEmitUTF8Identifier
)
public function UTF8Encoding (
    encoderShouldEmitUTF8Identifier : boolean
)

パラメータ

encoderShouldEmitUTF8Identifier

Unicode バイト順マーク付加するよう指定する場合trueそれ以外場合false

解説解説
使用例使用例

次の例は、エンコーディング時に Unicode バイト順マーク プリフィックス作成するよう指定して新しUTF8Encoding インスタンス作成する方法示してます。GetPreamble メソッドは、Unicode バイト順マーク プリフィックス返しコンソール表示します既定コンストラクタ使用して作成した UTF8Encoding には、Unicode バイト順マーク プリフィックスはありません。

Imports System
Imports System.Text

Class UTF8EncodingExample
    
    Public Shared Sub Main()
        Dim utf8 As New
 UTF8Encoding()
        Dim utf8EmitBOM As New
 UTF8Encoding(True)
        
        Console.WriteLine("utf8 preamble:")
        ShowArray(utf8.GetPreamble())
        
        Console.WriteLine("utf8EmitBOM:")
        ShowArray(utf8EmitBOM.GetPreamble())
    End Sub 'Main
    
    
    Public Shared Sub ShowArray(theArray
 As Array)
        Dim o As Object
        For Each o In  theArray
            Console.Write("[{0}]", o)
        Next o
        Console.WriteLine()
    End Sub 'ShowArray
End Class 'UTF8EncodingExample
using System;
using System.Text;

class UTF8EncodingExample {
    public static void Main()
 {
        UTF8Encoding utf8 = new UTF8Encoding();
        UTF8Encoding utf8EmitBOM = new UTF8Encoding(true);

        Console.WriteLine("utf8 preamble:");
        ShowArray(utf8.GetPreamble());

        Console.WriteLine("utf8EmitBOM:");
        ShowArray(utf8EmitBOM.GetPreamble());
    }

    public static void ShowArray(Array
 theArray) {
        foreach (Object o in theArray) {
            Console.Write("[{0}]", o);
        }
        Console.WriteLine();
    }
}
using namespace System;
using namespace System::Text;
using namespace System::Collections;
void ShowArray( Array^ theArray )
{
   IEnumerator^ myEnum = theArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Object^ o = safe_cast<Object^>(myEnum->Current);
      Console::Write( "[{0}]", o );
   }

   Console::WriteLine();
}

int main()
{
   UTF8Encoding^ utf8 = gcnew UTF8Encoding;
   UTF8Encoding^ utf8EmitBOM = gcnew UTF8Encoding( true );
   Console::WriteLine( "utf8 preamble:" );
   ShowArray( utf8->GetPreamble() );
   Console::WriteLine( "utf8EmitBOM:" );
   ShowArray( utf8EmitBOM->GetPreamble() );
}

import System.*;
import System.Text.*;

class UTF8EncodingExample
{
    public static void main(String[]
 args)
    {
        UTF8Encoding utf8 = new UTF8Encoding();
        UTF8Encoding utf8EmitBOM = new UTF8Encoding(true);

        Console.WriteLine("utf8 preamble:");
        ShowArray(utf8.GetPreamble());
        Console.WriteLine("utf8EmitBOM:");
        ShowArray(utf8EmitBOM.GetPreamble());
    } //main

    public static void ShowArray(Array
 theArray)
    {
        Object o = null;
        for (int iCtr = 0; iCtr < theArray.get_Length();
 iCtr++) {
            o = theArray.get_Item(iCtr);
            Console.Write("[{0}]", o);
        }
        Console.WriteLine();
    } //ShowArray
} //UTF8EncodingExample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
UTF8Encoding クラス
UTF8Encoding メンバ
System.Text 名前空間
GetPreamble

UTF8Encoding コンストラクタ




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

辞書ショートカット

すべての辞書の索引

「UTF8Encoding コンストラクタ ()」の関連用語

UTF8Encoding コンストラクタ ()のお隣キーワード
検索ランキング

   

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



UTF8Encoding コンストラクタ ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS