How to split an incoming string by character count

I've got a string coming into nodered from an external piece of equipment that I can't change. This is an example of what it shows on a debug node:

14711/17/20 12:53:10RUN 11/17/20 13:09:50MEURO26 SAMPLE5000 T170PS0CMM-A17001 393000108663 638 476 440.300045B99 11

The supplier has given me a start position and character count for each field but I'm struggling to work out how to do this.

any suggestions anyone?

thanks

Looks like you could split this using the space character in a split node.

If you want to use the character count method then in a function node you can use substr() to extract the text. https://www.w3schools.com/jsref/jsref_substr.asp

2 Likes

I thought that but was struggling to work out how to do multiple splits - any suggestions?

[{"id":"d8006259.f055f","type":"split","z":"37470995.f4f636","name":"","splt":" ","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":330,"y":100,"wires":[["f0fc9f75.ac45b"]]},{"id":"b16d9bc.45b0168","type":"inject","z":"37470995.f4f636","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"14711/17/20 12:53:10RUN 11/17/20 13:09:50MEURO26 SAMPLE5000 T170PS0CMM-A17001 393000108663 638 476 440.300045B99 11","payloadType":"str","x":170,"y":100,"wires":[["d8006259.f055f"]]},{"id":"70fb54eb.357d2c","type":"debug","z":"37470995.f4f636","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":100,"wires":[]},{"id":"f0fc9f75.ac45b","type":"join","z":"37470995.f4f636","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":490,"y":100,"wires":[["70fb54eb.357d2c"]]}]

Thanks, managed to get it working well using the substr() function

2 Likes

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