0

I am currently working on a small coding exercise on S7 1500 using ST(SCL) where 2 Arrays, A (being the bigger one in length) and B are compared with each other and checked for matching elements.

However the array B consists of alphanumeric characters and special characters (semicolon), for ex: "12345;12346B;12347A" etc unlike Array A which doesn't have a semicolon. I want to implement the Split functionality where the Delimiter or EndSeparator is ';' to separate the bunch of numbers and compare the split numbers with Array A elements to check if 12345 is present in Array A too.

I have used LOWER_BOUND and UPPER_BOUND for array limits since the range of Array A is undefined.

How do I go about this? Any pointers would be really appreciated. :)

For ref:

#LowerBound := LOWER_BOUND(ARR := #ARRAY_B, DIM := 1);
#UpperBound := UPPER_BOUND(ARR := #ARRAY_B, DIM := 1);

SPLIT(Mode:= _dword_in_, RecSeparator:=_variant_in_, EndSeparator:=_variant_in_, SrcArray:=_variant_in_, Count=>_udint_out_, DstStruct:=_variant_inout_, Position:=_udint_inout_)
Arjun
  • 9
  • 1
  • 7

1 Answers1

1

You can write your own SPLIT function.

FUNCTION SPLIT : ARRAY[0..255] OF STRING(250)
VAR_INPUT
    STR: STRING(250);
    CHAR: STRING(1);
END_VAR
VAR
    iPos: INT;
    sTest: STRING(250);
    iIndex: INT;
    xFinish: BOOL;
END_VAR

    sTest := STR;
    REPEAT
        iPos := FIND(sTest, CHAR);

        IF iPos = 0 THEN
            SPLIT[iIndex] := sTest;
            xFinish := TRUE;
        ELSE
            SPLIT[iIndex] := LEFT(sTest, iPos - 1);
            sTest := RIGHT(sTest, LEN(sTest) - iPos);
        END_IF;
        iIndex := iIndex + 1;
    UNTIL (xFinish = TRUE)
    END_REPEAT;

END_FUNCTION

And then in the code

VAR
    arsTest: ARRAY[0..255] OF STRING(250);
END_VAR

arsTest := SPLIT('12345;12346B;12347A', ';');
Sergey Romanov
  • 2,949
  • 4
  • 23
  • 38