UTF7Encoding.GetByteCount メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
一連の文字をエンコードすることによって生成されるバイト数を計算します。
オーバーロード
| 名前 | 説明 |
|---|---|
| GetByteCount(String) |
指定した String オブジェクト内の文字をエンコードすることによって生成されるバイト数を計算します。 |
| GetByteCount(Char*, Int32) |
指定した文字ポインターから始まる一連の文字をエンコードすることによって生成されるバイト数を計算します。 |
| GetByteCount(Char[], Int32, Int32) |
指定した文字配列から文字セットをエンコードすることによって生成されるバイト数を計算します。 |
GetByteCount(String)
指定した String オブジェクト内の文字をエンコードすることによって生成されるバイト数を計算します。
public:
override int GetByteCount(System::String ^ s);
public override int GetByteCount(string s);
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount(string s);
override this.GetByteCount : string -> int
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : string -> int
Public Overrides Function GetByteCount (s As String) As Integer
パラメーター
返品
指定した文字をエンコードすることによって生成されるバイト数。
- 属性
例外
s が null (Nothing) です。
結果のバイト数は、int として返すことができる最大数を超えています。
フォールバックが発生しました (詳細については、「character Encoding in .NET」を参照してください)。
および
EncoderFallback は EncoderExceptionFallback に設定されます。
例
次のコード例では、 GetByteCount メソッドを使用して、文字配列のエンコードに必要なバイト数を返す方法を示します。
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
// Unicode characters.
Char[] chars = new Char[] {
'\u0023', // #
'\u0025', // %
'\u03a0', // Pi
'\u03a3' // Sigma
};
UTF7Encoding utf7 = new UTF7Encoding();
int byteCount = utf7.GetByteCount(chars, 1, 2);
Console.WriteLine(
"{0} bytes needed to encode characters.", byteCount
);
}
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class UTF7EncodingExample
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 utf7 As New UTF7Encoding()
Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
End Sub
End Class
注釈
結果のバイト GetBytes 格納するために必要な正確な配列サイズを計算するために、アプリケーションは GetByteCountを使用します。 配列の最大サイズを計算するには、アプリケーションで GetMaxByteCountを使用する必要があります。 一般に、 GetByteCount メソッドではメモリの割り当てが少なくなりますが、 GetMaxByteCount メソッドの実行速度は一般的に速くなります。
こちらもご覧ください
適用対象
GetByteCount(Char*, Int32)
重要
この API は CLS 準拠ではありません。
指定した文字ポインターから始まる一連の文字をエンコードすることによって生成されるバイト数を計算します。
public:
override int GetByteCount(char* chars, int count);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
public override int GetByteCount(char* chars, int count);
[System.CLSCompliant(false)]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount(char* chars, int count);
[System.CLSCompliant(false)]
[System.Security.SecurityCritical]
[System.Runtime.InteropServices.ComVisible(false)]
public override int GetByteCount(char* chars, int count);
[System.CLSCompliant(false)]
public override int GetByteCount(char* chars, int count);
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
[<System.Security.SecurityCritical>]
[<System.Runtime.InteropServices.ComVisible(false)>]
override this.GetByteCount : nativeptr<char> * int -> int
[<System.CLSCompliant(false)>]
override this.GetByteCount : nativeptr<char> * int -> int
パラメーター
- chars
- Char*
エンコードする最初の文字へのポインター。
- count
- Int32
エンコードする文字数。
返品
指定した文字をエンコードすることによって生成されるバイト数。
- 属性
例外
chars は null (Visual Basic .NET では Nothing) です。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
EncoderFallback は EncoderExceptionFallback に設定されます。
注釈
結果のバイト GetBytes 格納するために必要な正確な配列サイズを計算するために、アプリケーションは GetByteCountを使用します。 配列の最大サイズを計算するには、アプリケーションで GetMaxByteCountを使用する必要があります。 一般に、 GetByteCount メソッドではメモリの割り当てが少なくなりますが、 GetMaxByteCount メソッドの実行速度は一般的に速くなります。
こちらもご覧ください
適用対象
GetByteCount(Char[], Int32, Int32)
指定した文字配列から文字セットをエンコードすることによって生成されるバイト数を計算します。
public:
override int GetByteCount(cli::array <char> ^ chars, int index, int count);
public override int GetByteCount(char[] chars, int index, int count);
override this.GetByteCount : char[] * int * int -> int
Public Overrides Function GetByteCount (chars As Char(), index As Integer, count As Integer) As Integer
パラメーター
- chars
- Char[]
エンコードする文字のセットを含む文字配列。
- index
- Int32
エンコードする最初の文字のインデックス。
- count
- Int32
エンコードする文字数。
返品
指定した文字をエンコードすることによって生成されるバイト数。
例外
chars が null (Nothing) です。
index または count が 0 未満です。
-または-
index および count は、 chars内の有効な範囲を示していません。
-または-
結果のバイト数は、int として返すことができる最大数を超えています。
フォールバックが発生しました (詳細については、「 .NET での文字エンコード」を参照してください)
および
EncoderFallback は EncoderExceptionFallback に設定されます。
例
次のコード例では、 GetByteCount メソッドを使用して、Unicode 文字の配列をエンコードするために必要なバイト数を返す方法を示します。
using System;
using System.Text;
class UTF7EncodingExample {
public static void Main() {
// Unicode characters.
Char[] chars = new Char[] {
'\u0023', // #
'\u0025', // %
'\u03a0', // Pi
'\u03a3' // Sigma
};
UTF7Encoding utf7 = new UTF7Encoding();
int byteCount = utf7.GetByteCount(chars, 1, 2);
Console.WriteLine(
"{0} bytes needed to encode characters.", byteCount
);
}
}
Imports System.Text
Imports Microsoft.VisualBasic.Strings
Class UTF7EncodingExample
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 utf7 As New UTF7Encoding()
Dim byteCount As Integer = utf7.GetByteCount(chars, 1, 2)
Console.WriteLine("{0} bytes needed to encode characters.", byteCount)
End Sub
End Class
注釈
結果のバイトを格納するために GetBytes に必要な正確な配列サイズを計算するために、アプリケーションは GetByteCountを使用します。 配列の最大サイズを計算するには、アプリケーションで GetMaxByteCountを使用する必要があります。 一般に、 GetByteCount メソッドではメモリの割り当てが少なくなりますが、 GetMaxByteCount メソッドの実行速度は一般的に速くなります。