I am using Twincat2 for an old project, and get a array of chars from a TCP connection.
a sample sting is this: CMD,011,132654,38201,ABC,23
I would need to split this into single strings. So basically an array of strings, where myarray[0] is CMD, [1] is 011 etc..
I cannot figure out how to do this. TC3 has a split function, but how can this be done in TC2 in structured text?
Thank you
CodePudding user response:
I have never used TC2, but here is how I would approach the problem:
- Find position of the first
,
using FIND
position := FIND(sampleString, ',');
- Assign characters up to this position to first string in the array using LEFT
myArray[0] := LEFT(sampleString, position-1);
- Delete first partial string and
,
from the initial string using DELETE
DELETE(sampleString, position, 1);
- Repeat until no
,
is found in the initial string, then assign what remains to the last element of the array