# Split string into text and integers

**URL:** <https://discourse.nodered.org/t/split-string-into-text-and-integers/49889>\
**Category:** General\
**Created:** [18 August 2021 22:08 UTC](https://discourse.nodered.org/t/split-string-into-text-and-integers/49889 "2021-08-18T22:08:34Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [19 August 2021 09:08 UTC](https://discourse.nodered.org/t/split-string-into-text-and-integers/49889/8 "2021-08-19T09:08:03Z")

</div>

You're right it would still be a string which is easily converted. To handle a variable number of spaces, here is a `change` node example using JSONata:

 ![Screen Shot 2021-08-19 at 5.01.11 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c38d75ca78af5aabc3d65ec0f884c7178dfa0f4d.png)  
rule 1 changes multiple spaces to one space  
rule 2 splits the string into an array of three items (no spaces)  
rule 3 grabs the second item in the array (the string characters of the number)  
rule 4 converts it to a number  
Here is the flow and with will handle decimal points in the number too

```auto
[{"id":"f8c2cb8c3cabfcba","type":"inject","z":"62c97fa4b68932fd","name":"SGWGross 1214 lb","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"SGWGross 1214 lb","payloadType":"str","x":310,"y":400,"wires":[["7263cf675a67d8d0","6d73fcef9ec1972d"]]},{"id":"1e7b99b2768829d2","type":"debug","z":"62c97fa4b68932fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":400,"wires":[]},{"id":"7263cf675a67d8d0","type":"change","z":"62c97fa4b68932fd","name":"change with 4 JSONata expressions","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim(payload)","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$split(payload,' ' )","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload[1]\t","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$number(payload)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":400,"wires":[["1e7b99b2768829d2"]]},{"id":"6d73fcef9ec1972d","type":"change","z":"62c97fa4b68932fd","name":"all four JSONata expressions in one","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($split($trim(payload),' ' )[1])\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":460,"wires":[["f5f5e29369843f72"]]},{"id":"f5f5e29369843f72","type":"debug","z":"62c97fa4b68932fd","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":930,"y":460,"wires":[]},{"id":"4c01b2334f2ce504","type":"inject","z":"62c97fa4b68932fd","name":"SGWGross 121.4 lb","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"SGWGross 121.4 lb","payloadType":"str","x":310,"y":480,"wires":[["6d73fcef9ec1972d","7263cf675a67d8d0"]]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/split-string-into-text-and-integers/49889)._
