Encoder.GetByteCount メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
派生クラスでオーバーライドされた場合、一連の文字をエンコードすることによって生成されるバイト数を計算します。
オーバーロード
| 名前 | 説明 |
|---|---|
| GetByteCount(ReadOnlySpan<Char>, Boolean) |
派生クラスでオーバーライドされた場合、'chars' スパンの文字セットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。 |
| GetByteCount(Char*, Int32, Boolean) |
派生クラスでオーバーライドされると、指定した文字ポインターから始まる文字のセットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。 |
| GetByteCount(Char[], Int32, Int32, Boolean) |
派生クラスでオーバーライドされた場合、指定した文字配列から文字セットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。 |
注釈
このメソッドは、エンコーダーの状態には影響しません。
結果のバイト GetBytes 格納するために必要な正確な配列サイズを計算するには、アプリケーションで GetByteCountを使用する必要があります。
flushを false に設定してGetBytesが呼び出されると、エンコーダーはデータ ブロックの末尾にある末尾の文字を内部バッファーに格納し、次のエンコード操作で使用します。 アプリケーションは、同じブロックでGetBytesを呼び出す直前に、データ ブロックのGetByteCountを呼び出して、前のブロックの末尾の文字が計算に含まれるようにする必要があります。
GetByteCount(ReadOnlySpan<Char>, Boolean)
派生クラスでオーバーライドされた場合、'chars' スパンの文字セットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。
public:
virtual int GetByteCount(ReadOnlySpan<char> chars, bool flush);
public virtual int GetByteCount(ReadOnlySpan<char> chars, bool flush);
abstract member GetByteCount : ReadOnlySpan<char> * bool -> int
override this.GetByteCount : ReadOnlySpan<char> * bool -> int
Public Overridable Function GetByteCount (chars As ReadOnlySpan(Of Char), flush As Boolean) As Integer
パラメーター
- chars
- ReadOnlySpan<Char>
エンコードする文字スパン。
- flush
- Boolean
true 計算後のエンコーダーの内部状態のクリアをシミュレートする場合。それ以外の場合は false。
返品
指定した文字と内部バッファー内の任意の文字をエンコードすることによって生成されるバイト数。
適用対象
GetByteCount(Char*, Int32, Boolean)
重要
この API は CLS 準拠ではありません。
派生クラスでオーバーライドされると、指定した文字ポインターから始まる文字のセットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。
public:
virtual int GetByteCount(char* chars, int count, bool flush);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public virtual int GetByteCount(char* chars, int count, bool flush);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
[System.Security.SecurityCritical]
public virtual int GetByteCount(char* chars, int count, bool flush);
[System.CLSCompliant(false)]
public virtual int GetByteCount(char* chars, int count, bool flush);
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
abstract member GetByteCount : nativeptr<char> * int * bool -> int
override this.GetByteCount : nativeptr<char> * int * bool -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
[<System.Security.SecurityCritical>]
abstract member GetByteCount : nativeptr<char> * int * bool -> int
override this.GetByteCount : nativeptr<char> * int * bool -> int
[<System.CLSCompliant(false)>]
abstract member GetByteCount : nativeptr<char> * int * bool -> int
override this.GetByteCount : nativeptr<char> * int * bool -> int
パラメーター
- chars
- Char*
エンコードする最初の文字へのポインター。
- count
- Int32
エンコードする文字数。
- flush
- Boolean
true 計算後のエンコーダーの内部状態のクリアをシミュレートする場合。それ以外の場合は false。
返品
指定した文字と内部バッファー内の任意の文字をエンコードすることによって生成されるバイト数。
- 属性
例外
chars は null (Visual Basic .NET では Nothing) です。
count が 0 未満です。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
Fallback は EncoderExceptionFallback に設定されます。
こちらもご覧ください
適用対象
GetByteCount(Char[], Int32, Int32, Boolean)
派生クラスでオーバーライドされた場合、指定した文字配列から文字セットをエンコードすることによって生成されるバイト数を計算します。 パラメーターは、計算後にエンコーダーの内部状態をクリアするかどうかを示します。
public:
abstract int GetByteCount(cli::array <char> ^ chars, int index, int count, bool flush);
public abstract int GetByteCount(char[] chars, int index, int count, bool flush);
abstract member GetByteCount : char[] * int * int * bool -> int
Public MustOverride Function GetByteCount (chars As Char(), index As Integer, count As Integer, flush As Boolean) As Integer
パラメーター
- chars
- Char[]
エンコードする文字のセットを含む文字配列。
- index
- Int32
エンコードする最初の文字のインデックス。
- count
- Int32
エンコードする文字数。
- flush
- Boolean
true 計算後のエンコーダーの内部状態のクリアをシミュレートする場合。それ以外の場合は false。
返品
指定した文字と内部バッファー内の任意の文字をエンコードすることによって生成されるバイト数。
例外
chars は nullです。
index または count が 0 未満です。
-または-
index および count は、 chars内の有効な範囲を示していません。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
Fallback は EncoderExceptionFallback に設定されます。
例
次のコード例では、 GetByteCount メソッドを使用して、Unicode Encoderを使用して文字の配列をエンコードするために必要なバイト数を返す方法を示します。
using System;
using System.Text;
class EncoderExample {
public static void Main() {
// Unicode characters.
Char[] chars = new Char[] {
'\u0023', // #
'\u0025', // %
'\u03a0', // Pi
'\u03a3' // Sigma
};
Encoder uniEncoder = Encoding.Unicode.GetEncoder();
int byteCount = uniEncoder.GetByteCount(chars, 0, chars.Length, true);
Console.WriteLine(
"{0} bytes needed to encode characters.", byteCount
);
}
}
/* This example produces the following output.
8 bytes needed to encode characters.
*/
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class EncoderExample
Public Shared Sub Main()
' Unicode characters.
' ChrW(35) = #
' ChrW(37) = %
' ChrW(928) = Pi
' ChrW(931) = Sigma
Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(928), ChrW(931)}
Dim uniEncoder As Encoder = Encoding.Unicode.GetEncoder()
Dim byteCount As Integer = _
uniEncoder.GetByteCount(chars, 0, chars.Length, True)
Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
End Sub
End Class
'
'This example produces the following output.
'
'8 bytes needed to encode characters.
'