Click or drag to resize

BinaryTextEncodingNullTerminated Method

Returns an encoder that will encode and decode null terminated string given a character encoding.

Namespace:  Demo3D.IO
Assembly:  Demo3D.IO (in Demo3D.IO.dll) Version: 15.0.2.11458
Syntax
C#
public static BinaryTextEncoding NullTerminated(
	Encoding characterEncoding
)

Parameters

characterEncoding
Type: System.TextEncoding
The character encoding.

Return Value

Type: BinaryTextEncoding
An instance of BinaryTextEncoding that will encode and decode strings in this format.
Examples

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

C#
public void NullTerminatedStrings(IDataReader receivedPacket, IDataWriter packetToSend) {
    // Reads bytes of data from 'receivedPacket' as an ASCII string until it reads the 'null' character.
    var str = receivedPacket.ReadString(BinaryTextEncoding.NullTerminatedASCII);

    // Writes the string "hello" into a packet as Unicode characters ready to be sent to the peer,
    // finishing it with a 'null' character.
    packetToSend.WriteString("hello", BinaryTextEncoding.NullTerminatedUnicode);
}
See Also