Split string based on ;

Hi,

I have a text file with location data when I use the 'file in' node i get strings with the format "A;B;C"

A,B,C don't have a consistent length. How can i split the string and return the value to

Msg.A
Msg.B
Msg.C
Msg.payload (original payload)

Sample data:

L1S3;52.61563261441822;4.0658098986827715

L1S1;52.44174022895096;6.384215548118491

Hello,

You can use the CSV node

Demo Flow:

[{"id":"b2dac34a6d1fcd85","type":"template","z":"54efb553244c241f","name":"data","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"L1S3;52.61563261441822;4.0658098986827715\nL1S1;52.44174022895096;6.384215548118491","output":"str","x":300,"y":1200,"wires":[["d76adacd90c1773f"]]},{"id":"df069b0fe53e1771","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":1200,"wires":[["b2dac34a6d1fcd85"]]},{"id":"d76adacd90c1773f","type":"csv","z":"54efb553244c241f","name":"","sep":";","hdrin":"","hdrout":"none","multi":"mult","ret":"\\n","temp":"A, B, C","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":420,"y":1200,"wires":[["2694dcd575e2d741"]]},{"id":"2694dcd575e2d741","type":"debug","z":"54efb553244c241f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1200,"wires":[]}]

image

2 Likes

The csv node is an excellent choice. Another option is,

node-red-contrib-string

This node has options to parse values to array elements. This should be the easiest way to do the most (string operations) without programming. You can also run multiple commands in succession to your input string(s).

2 Likes

To manage keeping your original payload value, you can simply use a "Change" node to shift/copy the payload to another element in your message. You can call it "original_payload" or whatever you like. Then retrieve it by shifting it back to the payload after you manage the results of the split elements.

1 Like

An other solution and better for getting separate messages is using a split node.

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