Teilen über


BinaryFormat.Text

Syntax

BinaryFormat.Text(length as any, optional encoding as nullable number) as function 

About

Gibt ein Binärformat zurück, das einen Textwert liest. The length specifies the number of bytes to decode, or the binary format of the length that precedes the text. Der optionale encoding Wert gibt die Codierung des Texts an. Wenn dies encoding nicht angegeben ist, wird die Codierung aus den Unicode-Bytereihenfolgenzeichen bestimmt. Wenn keine Bytereihenfolgenzeichen vorhanden sind, wird sie TextEncoding.Utf8 verwendet.

Beispiel 1

Decodieren Sie zwei Bytes als ASCII-Text.

Verwendung

let
    binaryData = #binary({65, 66, 67}),
    textFormat = BinaryFormat.Text(2, TextEncoding.Ascii)
in
    textFormat(binaryData)

Output

"AB"

Beispiel 2

Decodieren Sie ASCII-Text, wobei die Länge des Texts in Byte vor dem Text als Byte angezeigt wird.

Verwendung

let
    binaryData = #binary({2, 65, 66}),
    textFormat = BinaryFormat.Text(
        BinaryFormat.Byte,
        TextEncoding.Ascii
    )
in
    textFormat(binaryData)

Output

"AB"