最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Control characters as delimiters - Stack Overflow

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论