Gio Borje
Gio Borje

Reputation: 21114

Control characters as delimiters

I have a nodejs TCP 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.

Upvotes: 3

Views: 5463

Answers (2)

Yana Lazer
Yana Lazer

Reputation: 61

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

Upvotes: 0

Josh Gao
Josh Gao

Reputation: 2564

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.

Upvotes: 5

Related Questions