BinaryTextEncodingStringDelimited Method |
Namespace: Demo3D.IO
public static BinaryTextEncoding StringDelimited( string header, string footer, Encoding characterEncoding = null )
The following example shows simple examples for reading and writing strings.
public void StringDelimitedStrings(IDataReader receivedPacket, IDataWriter packetToSend) { // 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. var str = receivedPacket.ReadString(BinaryTextEncoding.StringDelimited("<<", ">>")); // The string is terminated with a '|' character. Effectively the protocol uses strings separated with '|'. str = receivedPacket.ReadString(BinaryTextEncoding.StringDelimited(null, "|")); // The standard STX ETX encapsulated format. const string stx = "\u0002"; const string etx = "\u0003"; str = receivedPacket.ReadString(BinaryTextEncoding.StringDelimited(stx, etx)); // Writes the string "hello" prepended with the STX character and appended with the ETX character. packetToSend.WriteString("hello", BinaryTextEncoding.StringDelimited(stx, etx)); }