I have a nodejs TCP server and a client. Basic network munication happens. Client sends "data + STX_CHARACTER + data + ETX_CHARACTER" (just an example).
How do I split the string using the STX Control Character as a delimiter or how do I reference the character at all in Javascript.
I have a nodejs TCP server and a client. Basic network munication happens. Client sends "data + STX_CHARACTER + data + ETX_CHARACTER" (just an example).
How do I split the string using the STX Control Character as a delimiter or how do I reference the character at all in Javascript.
Share Improve this question edited May 18, 2010 at 6:13 Justin Johnson 31.3k7 gold badges66 silver badges89 bronze badges asked May 18, 2010 at 5:16 Gio BorjeGio Borje 21.1k7 gold badges39 silver badges50 bronze badges2 Answers
Reset to default 5STX and ETX are characters 0x02 and 0x03 respectively, so it'd just be "\2" and "\3". Just use string.split("\2") and .split("\3") on the second chunk from the first split to get your data.
For example you need to split string by Control character (0x17).It is equal to Decimal 23. So you do simple this: console.log(yourString.split(String.fromCharCode(23)));