Base64FormattingOptions Base64FormattingOptions Base64FormattingOptions Base64FormattingOptions Enum

定義

関連する ToBase64CharArray メソッドと ToBase64String メソッドで、それぞれの出力に改行を挿入するかどうかを指定します。Specifies whether relevant ToBase64CharArray and ToBase64String methods insert line breaks in their output.

この列挙型には FlagsAttribute 属性があり、メンバー値ではビットごとの組み合わせを使用できます。

public enum class Base64FormattingOptions
[System.Flags]
public enum Base64FormattingOptions
type Base64FormattingOptions = 
Public Enum Base64FormattingOptions
継承
Base64FormattingOptionsBase64FormattingOptionsBase64FormattingOptionsBase64FormattingOptions
属性

フィールド

InsertLineBreaks InsertLineBreaks InsertLineBreaks InsertLineBreaks 1

文字列形式で 76 文字ごとに改行を挿入します。Inserts line breaks after every 76 characters in the string representation.

None None None None 0

文字列形式で 76 文字ごとに改行を挿入しません。Does not insert line breaks after every 76 characters in the string representation.

次の例では、 Convert.ToBase64String(Byte[], Base64FormattingOptions) 100 要素のバイト配列をエンコードすることによって生成される文字列で、InsertLineBreaks で行を挿入する引数が中断されます。The following example calls the Convert.ToBase64String(Byte[], Base64FormattingOptions) with a InsertLineBreaks argument to insert line breaks in the string that is produced by encoding a 100-element byte array.

using System;

public class Example
{
   public static void Main()
   {
       // Define a byte array.
       var bytes = new byte[100];
       int originalTotal = 0;
       for (int ctr = 0; ctr <= bytes.GetUpperBound(0); ctr++) {
          bytes[ctr] = (byte)(ctr + 1);
          originalTotal += bytes[ctr];
       }
       // Display summary information about the array.
       Console.WriteLine("The original byte array:");
       Console.WriteLine("   Total elements: {0}", bytes.Length);
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(bytes).Length);
       Console.WriteLine("   Sum of elements: {0:N0}", originalTotal);                  
       Console.WriteLine();
       
       // Convert the array to a base 64 string.
       string s = Convert.ToBase64String(bytes, 
                                         Base64FormattingOptions.InsertLineBreaks);
       Console.WriteLine("The base 64 string:\n   {0}\n", s);
       
       // Restore the byte array.
       Byte[] newBytes = Convert.FromBase64String(s);
       int newTotal = 0;
       foreach (var newByte in newBytes)
          newTotal += newByte;

       // Display summary information about the restored array.
       Console.WriteLine("   Total elements: {0}", newBytes.Length);
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(newBytes).Length);
       Console.WriteLine("   Sum of elements: {0:N0}", newTotal);                  
   }
}
// The example displays the following output:
//   The original byte array:
//      Total elements: 100
//      Length of String Representation: 299
//      Sum of elements: 5,050
//   
//   The base 64 string:
//      AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5
//   Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==
//   
//      Total elements: 100
//      Length of String Representation: 299
//      Sum of elements: 5,050
Module Example
   Public Sub Main()
       ' Define a byte array.
       Dim bytes(99) As Byte
       Dim originalTotal As Integer = 0
       For ctr As Integer = 0 To bytes.GetUpperBound(0)
          bytes(ctr) = CByte(ctr + 1)
          originalTotal += bytes(ctr)
       Next
       ' Display summary information about the array.
       Console.WriteLine("The original byte array:")
       Console.WriteLine("   Total elements: {0}", bytes.Length)
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(bytes).Length)
       Console.WriteLine("   Sum of elements: {0:N0}", originalTotal)                  
       Console.WriteLine()
       
       ' Convert the array to a base 64 string.
       Dim s As String = Convert.ToBase64String(bytes, 
                                               Base64FormattingOptions.InsertLineBreaks)
       Console.WriteLine("The base 64 string:{1}   {0}{1}", 
                         s, vbCrLf)
       
       ' Restore the byte array.
       Dim newBytes() As Byte = Convert.FromBase64String(s)
       Dim newTotal As Integer = 0
       For Each newByte In newBytes
          newTotal += newByte
       Next
       ' Display summary information about the restored array.
       Console.WriteLine("   Total elements: {0}", newBytes.Length)
       Console.WriteLine("   Length of String Representation: {0}",
                         BitConverter.ToString(newBytes).Length)
       Console.WriteLine("   Sum of elements: {0:N0}", newTotal)                  
   End Sub
End Module
' The example displays the following output:
'   The original byte array:
'      Total elements: 100
'      Length of String Representation: 299
'      Sum of elements: 5,050
'   
'   The base 64 string:
'      AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5
'   Ojs8PT4/QEFCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaW1xdXl9gYWJjZA==
'   
'      Total elements: 100
'      Length of String Representation: 299
'      Sum of elements: 5,050

例を示しますから出力として、Convert.FromBase64String元のバイト配列の復元に成功すると、変換中に、改行文字は無視されます。As the output from the example shows, the Convert.FromBase64String succeeds in restoring the original byte array; the line break characters are ignored during the conversion.

注釈

Convert.ToBase64CharArrayConvert.ToBase64Stringメソッドでは、8 ビット符号なし整数の配列の値を base64 の数字で構成される等価の文字列形式に変換します。The Convert.ToBase64CharArray and Convert.ToBase64String methods convert the value of an array of 8-bit unsigned integers to an equivalent string representation that consists of base 64 digits. 文字列の形式は 1 つを含めることができます、または、復帰と改行が定義されている複数の改行文字 (U+000D) の後に改行文字 (u+000 a) を返します。The string representation can contain one or more line breaks, where a line break is defined as a carriage return character (U+000D) followed by a line feed character (U+000A). 改行は、base 64 エンコードでの空白文字と見なされる、ために、エンコードされたバイト配列に文字列の base 64 に変換するときは無視されます。Because line breaks are considered white-space characters in a base-64 encoding, they are ignored when converting a base-64 encoded string back to a byte array. コントロールまたはコンソール ウィンドウなどのデバイスに、エンコードされた文字列を表示するときに、改行を単に便利です。The line breaks are simply convenient when displaying the encoded string to a control or a device such as a console window.

"なし"InsertLineBreaks 値は相互に排他的であるとします。The None and InsertLineBreaks values are mutually exclusive. そのため、ですが、Base64FormattingOptions.None列挙が付いて、FlagsAttribute属性、意味がないこれら 2 つの値のビットごとの組み合わせを実行します。Therefore, although the Base64FormattingOptions.None enumeration is marked with the FlagsAttribute attribute, it makes no sense to perform a bitwise combination of these two values.

適用対象