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

**URL:** <https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188>\
**Category:** General\
**Created:** [19 October 2023 13:00 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188 "2023-10-19T13:00:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 October 2023 13:00 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188/1 "2023-10-19T13:00:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [19 October 2023 13:08 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188/2 "2023-10-19T13:08:30Z")

</div>

Hi @cymplecy

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

pass in `startIndex` along with your `msg`

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e7b843a5adca1a64883f04a32433ea0b856b070.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [19 October 2023 13:28 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188/3 "2023-10-19T13:28:18Z")

</div>

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

```auto
[{"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":[]}] 

```

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [19 October 2023 13:43 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188/4 "2023-10-19T13:43:19Z")

</div>

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

---

<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:** [2 November 2023 13:43 UTC](https://discourse.nodered.org/t/how-to-achieve-a-simple-string-slice-without-using-function-node/82188/5 "2023-11-02T13:43:30Z")

</div>

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