BinaryTextEncodingStxEtx Property |
Namespace: Demo3D.IO
The following example shows simple examples for reading and writing strings.
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); }