# Help how to work with \`string\` node

**URL:** <https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691>\
**Category:** General\
**Created:** [30 September 2021 00:12 UTC](https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691 "2021-09-30T00:12:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [30 September 2021 00:12 UTC](https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691/1 "2021-09-30T00:12:25Z")

</div>

Problem:

Incoming message:  
`rgb,x,r,g,b`

limits:  
`x` 0 - 7  
`r`,`g`,`b` 0 - 255

This is the base flow:

```auto
[{"id":"33f88dd62e9a1854","type":"string","z":"65c9b63cb09879a0","name":"","methods":[{"name":"delLeftMost","params":[{"type":"str","value":"rgb,"}]},{"name":"left","params":[{"type":"num","value":"1"}]},{"name":"toInteger","params":[]}],"prop":"payload","propout":"pointer","object":"msg","objectout":"msg","x":2770,"y":160,"wires":[["9e72ba1e6e745ccf","d72327bb.0bc37"]]},{"id":"349b67738dfc8261","type":"inject","z":"65c9b63cb09879a0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,4,0,0,0","payloadType":"str","x":2610,"y":160,"wires":[["33f88dd62e9a1854"]]},{"id":"9e72ba1e6e745ccf","type":"debug","z":"65c9b63cb09879a0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"pointer","targetType":"msg","statusVal":"payload","statusType":"auto","x":2960,"y":160,"wires":[]},{"id":"d72327bb.0bc37","type":"string","z":"65c9b63cb09879a0","name":"0","methods":[{"name":"chompLeft","params":[{"type":"str","value":"rgb,4,"}]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2810,"y":220,"wires":[["ee603826871cfe95"]]},{"id":"ee603826871cfe95","type":"function","z":"65c9b63cb09879a0","name":"","func":"let pointer = msg.pointer;\n\n\nflow.set(\"test[\"+pointer+\"]\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2980,"y":220,"wires":[[]]}]

```

Needed:  
To not need 8 nodes, I want to set an array depending on the RGB values.

Look in the `function` node.

```auto
let pointer = msg.pointer;
flow.set("test["+pointer+"]",msg.payload);

```

Doesn't work.

I need to get the second `string` node to remove the first 6 characters.

For reasons unknown I am at a loss what _command_ (option?) I need to use in the string node.

---

<div class="post-metadata">

**Author:** ![LosinIt](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LosinIt](https://discourse.nodered.org/u/LosinIt)\
**Post date:** [30 September 2021 02:49 UTC](https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691/2 "2021-09-30T02:49:14Z")

</div>

I guess you're using node-red-contrib-string which I have not and I'll go out on a limb here because I'm not that experienced with NR but I _think_ you want something like this in a function node instead of node-red-contrib-string.

Assuming that msg.payload contains "rgb,x,r,g,b" you can use ".split", because the values are comma-separated, like so:

```auto
var array = msg.payload.split(",");

// Which puts each element into the array thus:

array[0] will have the rgb value
array[1] will have the x value
array[2] will have the r value
array[3] will have the g value
array[4] will have the b value

```

HTH

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [30 September 2021 02:58 UTC](https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691/3 "2021-09-30T02:58:48Z")

</div>

Thanks.

I may do that.... I accept that I will then have to re-build the latter part of the message, but that isn't a deal breaker for this scenario.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 November 2021 02:59 UTC](https://discourse.nodered.org/t/help-how-to-work-with-string-node/51691/4 "2021-11-29T02:59:00Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
