base 64 の数字で構成される Unicode 文字配列の指定サブセットを等価の 8 ビット符号なし整数の配列に変換します。パラメータにより、入力配列のオフセットとしてのサブセットと、変換する配列の要素の数が指定されます。
Public Shared Function FromBase64CharArray( _
ByVal inArray() As Char, _ ByVal offset As Integer, _ ByVal length As Integer _) As Byte()
[C#]
public static byte[] FromBase64CharArray(char[] inArray,intoffset,intlength);
[C++]
public: static unsigned char FromBase64CharArray(__wchar_tinArray __gc[],intoffset,intlength) __gc[];
[JScript]
public static function FromBase64CharArray(
inArray : Char[],offset : int,length : int) : Byte[];
パラメータ
- inArray
Unicode 文字配列。 - offset
inArray 内での位置。 - length
変換する inArray の要素の数。
戻り値
inArray の offset の位置にある length 要素と等価の 8 ビット符号なし整数の配列。
例外
例外の種類 | 条件 |
---|---|
ArgumentNullException | inArray が null 参照 (Visual Basic では Nothing) です。 |
ArgumentOutOfRangeException | offset または length が 0 未満です。
または length に offset を足した数が、 inArray 内に存在しない位置を示しています。 |
FormatException | 空白文字を除いた inArray の長さが 4 未満です。
または 空白文字を除いた inArray の長さが 4 の倍数ではありません。 |
解説
inArray は、Base64 形式の文字、空白文字、および後続の埋め込み文字で構成されます。Base64 形式の文字を 0 から昇順で並べると、大文字の 'A' ~ 'Z'、小文字の 'a' ~ 'z'、数字の '0' ~ '9'、および '+' と '/' の記号になります。
空白文字とは、タブ、空白、キャリッジ リターン、および改行のことを指します。空白文字はすべて無視されるため、任意の数の空白文字を inArray に含めることができます。
値として解釈されない文字 '=' は、文字列末尾の埋め込み用に使用されます。 inArray の末尾は、1 つまたは 2 つの埋め込み文字で構成されます。
使用例
[Visual Basic, C#, C++] FromBase64CharArray メソッドを使用して、UU エンコードされた (base 64 形式) データをデコードし、バイナリ出力として保存する方法を次の例に示します。
Public Sub DecodeWithCharArray()
Dim inFile As System.IO.StreamReader
Dim base64CharArray() As Char
Try
inFile = New System.IO.StreamReader(inputFileName, _
System.Text.Encoding.ASCII)
ReDim base64CharArray(inFile.BaseStream.Length - 1)
inFile.Read(base64CharArray, 0, inFile.BaseStream.Length)
inFile.Close()
Catch exp As System.Exception
' Error creating stream or reading from it.
System.Console.WriteLine("{0}", exp.Message)
Return
End Try
' Convert the Base64 UUEncoded input into binary output.
Dim binaryData() As Byte
Try
binaryData = System.Convert.FromBase64CharArray(base64CharArray, 0, _
base64CharArray.Length)
Catch exp As System.ArgumentNullException
System.Console.WriteLine("Base 64 character array is null.")
Return
Catch exp As System.FormatException
System.Console.WriteLine("Base 64 Char Array length is not " + _
"4 or is not an even multiple of 4")
Return
End Try
' Write out the decoded data.
Dim outFile As System.IO.FileStream
Try
outFile = New System.IO.FileStream(outputFileName, _
System.IO.FileMode.Create, _
System.IO.FileAccess.Write)
outFile.Write(binaryData, 0, binaryData.Length - 1)
outFile.Close()
Catch exp As System.Exception
' Error creating stream or writing to it.
System.Console.WriteLine("{0}", exp.Message)
End Try
End Sub
[C#]
public void DecodeWithCharArray() {
System.IO.StreamReader inFile;
char[] base64CharArray;
try {
inFile = new System.IO.StreamReader(inputFileName,
System.Text.Encoding.ASCII);
base64CharArray = new char[inFile.BaseStream.Length];
inFile.Read(base64CharArray, 0, (int)inFile.BaseStream.Length);
inFile.Close();
}
catch (System.Exception exp) {
// Error creating stream or reading from it.
System.Console.WriteLine("{0}", exp.Message);
return;
}
// Convert the Base64 UUEncoded input into binary output.
byte[] binaryData;
try {
binaryData =
System.Convert.FromBase64CharArray(base64CharArray,
0,
base64CharArray.Length);
}
catch ( System.ArgumentNullException ) {
System.Console.WriteLine("Base 64 character array is null.");
return;
}
catch ( System.FormatException ) {
System.Console.WriteLine("Base 64 Char Array length is not " +
"4 or is not an even multiple of 4." );
return;
}
// Write out the decoded data.
System.IO.FileStream outFile;
try {
outFile = new System.IO.FileStream(outputFileName,
System.IO.FileMode.Create,
System.IO.FileAccess.Write);
outFile.Write(binaryData, 0, binaryData.Length);
outFile.Close();
}
catch (System.Exception exp) {
// Error creating stream or writing to it.
System.Console.WriteLine("{0}", exp.Message);
}
}
[C++]
public:
void DecodeWithCharArray() {
StreamReader* inFile;
Char base64CharArray[];
try {
inFile = new StreamReader(inputFileName,
Text::Encoding::ASCII);
base64CharArray = new Char[(int)(inFile->BaseStream->Length)];
inFile->Read(base64CharArray, 0, (int)inFile->BaseStream->Length);
inFile->Close();
} catch (Exception* exp) {
// Error creating stream or reading from it.
Console::WriteLine(S" {0}", exp->Message);
return;
}
// Convert the Base64 UUEncoded input into binary output.
Byte binaryData[];
try {
binaryData =
Convert::FromBase64CharArray(base64CharArray,
0,
base64CharArray->Length);
} catch (ArgumentNullException*) {
Console::WriteLine(S"Base 64 character array is null.");
return;
} catch (FormatException*) {
Console::WriteLine(S"Base 64 Char Array length is not 4 or is not an even multiple of 4.");
return;
}
// Write out the decoded data.
FileStream* outFile;
try {
outFile = new FileStream(outputFileName,
FileMode::Create,
FileAccess::Write);
outFile->Write(binaryData, 0, binaryData->Length);
outFile->Close();
} catch (Exception* exp) {
// Error creating stream or writing to it.
Console::WriteLine(S" {0}", exp->Message);
}
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET