6 hex numbers to 3 * 2 hex split

I have ABCDEF - 6 hex numbers coming to node red however need them separate into 3 lots of 2 hex numbers left to right AB first CD second and etc. using function module in node red.

Use the JavaScript slice() twice. Here is a link for you
https://www.w3schools.com/jsref/jsref_slice_string.asp

Thank you for reply, but that doesn't work for me.

I'm referring to HEX values in payload not strings.

JavaScript does not have a variable type HEX. What type is the data? Number, buffer, or what? Feed it into a debug node and see what it shows.

Hi, thanks for taking time to help me
Debug message is:

I'm using "colour picker" in dashboard to generate color
and message I get
msg.payload : string[7]
"#b3624c" which is HEX number

In this case
b3 would be RED (179 DEC)
62 would be GREEN (98 DEC)
4c would be BLUE (76 DEC)
or do I need to use different method to achieve that?

it's a string not a hex number (no such thing)

Use the slice function @zenofmud suggested to create 3 two character parts then you can use parseInt to convert the 3 hex strings to numbers.

[{"id":"a22d044f.37e61","type":"debug","z":"6cf58c60.5c2ec4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":2220,"wires":[]},{"id":"49cd18b5.1d00d8","type":"function","z":"6cf58c60.5c2ec4","name":"","func":"str == msg.payload;\nmsg == str.split(4,2);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":2220,"wires":[["a22d044f.37e61"]]},{"id":"45d91520.88ed9c","type":"inject","z":"6cf58c60.5c2ec4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"123456","payloadType":"str","x":330,"y":2220,"wires":[["49cd18b5.1d00d8"]]}]

I'm stuck

You don't seem to using the slice function, as suggested.

Also don't forget to include the # character in your test inject node.

Msg must be an object so you need to set msg.payload to the result

Of course you could set the ui Color picker to output a more suitable choice of objects

Hi , and thanks.

I'm new to this and getting nowhere with this.

can someone please write me exact solution that I place into Function node that will work,
for what I need.

Thank you in advance

msg.payload = msg.payload.match(/[^#]{1,2}/g);
return msg;

that should return ["b3", "62", "4c"]. So payload[0] would be "b3" and payload[1] would be 62, etc.

1 Like

Thank you for solution that works good,

sorry if there is bit off confusion,
I was not aware that there is actual
' split node ' as my was hidden.
Thank you again