System Namespace Convert Class
Converts the specified subset of an array of Unicode characters consisting of base 64 digits to an equivalent array of 8-bit unsigned integers. Parameters specify the offset and number of elements in the input array.
[ VB ]
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,
int offset,
int length
);
[ C++ ]
public: static unsigned char FromBase64CharArray (
__wchar_t inArray __gc [ ],
int offset,
int length
) __gc [ ];
[ JScript ]
public static function FromBase64CharArray (
inArray : Char[ ],
offset : int,
length : int
) : Byte[ ];
- inArray
- A Unicode character array.
- offset
- A position within inArray.
- length
- The number of elements in inArray to convert.
An array of 8-bit unsigned integers equivalent to length elements at position offset in inArray.
Exception Type |
Condition |
ArgumentNullException |
inArray is a null reference ( Nothing in Visual Basic ). |
ArgumentOutOfRangeException |
offset or length is less than 0.
-or-
offset plus length indicates a position not within inArray.
|
FormatException |
The length of inArray is less than 4.
-or-
The length of inArray is not an even multiple of 4.
|
The subset in inArray is composed of base 64 digits. The base 64 digits in ascending order from zero are the uppercase characters 'A' to 'Z', lowercase characters 'a' to 'z', numerals '0' to '9', and the symbols '+' and '/'. The valueless character, '=', is used for trailing padding.
The following sample demonstrates using the FromBase64CharArray method.
[ VB ]
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.Response.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.Response.WriteLine ( "Base 64 character array is null." )
Return
Catch exp As System.FormatException
System.Response.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.Response.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.Response.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.Response.WriteLine ( "Base 64 character array is null." );
return;
}
catch ( System.FormatException ) {
System.Response.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.Response.WriteLine ( "{0}", exp.Message );
}
}
Convert Members