How to achieve a simple string slice without using function node :)

I'm wanting to convert

1234abcdef
into
abcdef i.e. remove the 1st n chars in the text where n is variable (but can be set in a config node)

I tried playing with node-red-contrib-string but couldn't make it do the job (which surprised me)

Can anyone make the string node do the job or got an alternative (Non-JS/Non-JSONata) solution?

Hi @cymplecy

I think maybe the Change node using JSONata should do it?

pass in startIndex along with your msg

image

1 Like

Non Javascript, JSONata way using standard nodes. using a config variable.
Hope I understood correctly

[{"id":"c179285a0ade03a8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"config","v":"4","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1234abcdef","payloadType":"str","x":170,"y":4840,"wires":[["26ea6e6e9f2aa387"]]},{"id":"26ea6e6e9f2aa387","type":"split","z":"b779de97.b1b46","name":"","splt":"1","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":350,"y":4840,"wires":[["0d37189831e1615f"]]},{"id":"0d37189831e1615f","type":"switch","z":"b779de97.b1b46","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"gte","v":"config","vt":"msg"}],"checkall":"true","repair":true,"outputs":1,"x":470,"y":4840,"wires":[["6ad21c2f98d46814"]]},{"id":"6ad21c2f98d46814","type":"join","z":"b779de97.b1b46","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":590,"y":4840,"wires":[["584b1553b0a13d8e"]]},{"id":"584b1553b0a13d8e","type":"debug","z":"b779de97.b1b46","name":"debug 346","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":4900,"wires":[]}] 
2 Likes

I'd forgotten about using split/join - ta for reminding me :slight_smile:

1 Like

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