Click or drag to resize

BinaryTextEncodingStringDelimited Method

Returns an encoder that will encode and decode string-delimited strings given a character encoding.

Namespace: Demo3D.IO
Assembly: Demo3D.IO (in Demo3D.IO.dll) Version: 19.01.00
Syntax
C#
public static BinaryTextEncoding StringDelimited(
	string header,
	string footer,
	Encoding? characterEncoding = null
)

Parameters

header  String
The expected string header (or null).
footer  String
The string footer/delimiter.
characterEncoding  Encoding  (Optional)
The character encoding. (Defaults to ASCII.)

Return Value

BinaryTextEncoding
An instance of BinaryTextEncoding that will encode and decode strings in this format.
Example

The following example shows simple examples for reading and writing strings.

C#
public string StringDelimitedStrings(IDataReader receivedPacket) {
    // The string to be read will start with '<<' and end with '>>'.  The string returned will have the
    // quotes ('<<' and '>>') stripped off.  Just the original string between the quotes will be returned.
    return receivedPacket.ReadString(BinaryTextEncoding.StringDelimited("<<", ">>"));
}

public string PipeDelimitedStrings(IDataReader receivedPacket) {
    // The string is terminated with a '|' character.  Effectively the protocol uses strings separated with '|'.
    return receivedPacket.ReadString(BinaryTextEncoding.StringDelimited(null, "|"));
}

public void StxEtxDelimitedStrings(IDataReader receivedPacket, IDataWriter packetToSend) {
    // The standard STX ETX encapsulated format.
    var str = receivedPacket.ReadString(BinaryTextEncoding.StxEtx);

    // Writes the string "hello" prepended with the STX character and appended with the ETX character.
    packetToSend.WriteString("hello", BinaryTextEncoding.StxEtx);
}
See Also