Split string into text and integers

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:


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

[{"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"]]}]
2 Likes