Base64FormattingOptions 열거형
정의
관련 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
[<System.Flags>]
type Base64FormattingOptions =
Public Enum Base64FormattingOptions
- 상속
- 특성
필드
InsertLineBreaks | 1 | 문자열 표현에서 76자마다 줄 바꿈을 삽입합니다.Inserts line breaks after every 76 characters in the string representation. |
None | 0 | 문자열 표현에서 76자마다 줄 바꿈을 삽입하지 않습니다.Does not insert line breaks after every 76 characters in the string representation. |
예제
다음 예제에서는 인수를 사용 하 여 메서드를 호출 Convert.ToBase64String(Byte[], Base64FormattingOptions) InsertLineBreaks
하 여 100 요소 바이트 배열을 인코딩하여 생성 되는 문자열에 줄 바꿈을 삽입 합니다.The following example calls the Convert.ToBase64String(Byte[], Base64FormattingOptions) method 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.ToBase64CharArray및 Convert.ToBase64String 메서드는 8 비트 부호 없는 정수로 구성 된 배열의 값을 기본 64 자릿수로 구성 된 해당 문자열 표현으로 변환 합니다.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. 문자열 표현은 줄 바꿈을 하나 이상 포함할 수 있습니다. 여기서 줄 바꿈은 캐리지 리턴 문자 (U + 000D)와 줄 바꿈 문자 (U + 000A)로 정의 됩니다.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.
None
및 InsertLineBreaks
값은 함께 사용할 수 없습니다.The None
and InsertLineBreaks
values are mutually exclusive. 따라서 Base64FormattingOptions
열거형은 특성으로 표시 되지만 FlagsAttribute 이러한 두 값의 비트 조합을 수행 하는 것은 의미가 없습니다.Therefore, although the Base64FormattingOptions
enumeration is marked with the FlagsAttribute attribute, it makes no sense to perform a bitwise combination of these two values.