Control characters as delimiters
I have a nodejs TCP 开发者_JS百科server and a client. Basic network communication 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.
STX 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)));
精彩评论