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: 19.01.00
Syntax
C#
public static BinaryTextEncoding NullTerminated(
	Encoding characterEncoding
)

Parameters

characterEncoding  Encoding
The character encoding.

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 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