admin管理员组

文章数量:1392047

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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

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

本文标签: javascriptControl characters as delimitersStack Overflow