Control characters as delimiters

I have nodejs TCP server and client. There is a basic network connection. The client sends "data + STX_CHARACTER + data + ETX_CHARACTER" (just an example).

How to split a string using an STX control character as a delimiter, or how I generally refer to a character in Javascript.

+3
source share
2 answers

STX and ETX are the characters 0x02 and 0x03 respectively, so it will just be "\ 2" and "\ 3". Just use string.split ("\ 2") and .split ("\ 3") in the second fragment from the first fragment to get your data.

+4
source

, (0x17). 23. , : console.log(yourString.split(String.fromCharCode(23)));

0

Source: https://habr.com/ru/post/1745921/


All Articles