String functions

This test case it part of the test suite proposed for new devices.

Test case ID: R0160
Language: ST

Code:
tests2/t0160.st

PROGRAM TEST_R0160  // pag 63
    VAR
        s2,s3,s4,s5,s6,s7, s8: STRING;
        u1,u2 : STRING;        
        ts1,ts2,ts3 : STRING;
        i1,i2,i9 : INT;
        b1 : BOOL;
                fb: FB3;
    END_VAR
    i1 := 12;
    i1 := LEN(STRING#'ASTRING');
    _GEB_ASSERT_(i1 = 7);
    i2 := LEN('$C4STRING'); // ÄSTRING (A with dieresis, in ISO-8859-1)
    _GEB_ASSERT_(i2 = 7);
    s2 := LEFT( IN:= 'A$53TR', L := 3 ); // 'ASTR'
    _GEB_ASSERT_(s2 = 'AST');
    s3 := RIGHT( IN:= 'ASTR', L := 3 ); 
    _GEB_ASSERT_(s3 = 'STR');
    s4 := MID( IN:= 'ABTRWXYZ', L := 3 , P := 2 ); 
    _GEB_ASSERT_(s4 = 'BTR');
    
    s8 := REPLACE( IN1:= 'ABCDE', IN2 := 'X', L := 2 , P :=3 ); 
    _GEB_ASSERT_(s8 = 'ABXE');
    
    s8 := REPLACE( IN1:= 'ABCDE', IN2 := 'X', L := 4 , P :=1 ); 
    _GEB_ASSERT_(s8 = 'XE');
    s8 := REPLACE( IN1:= 'ABCDE', IN2 := 'X', L := 4 , P :=2 ); 
    _GEB_ASSERT_(s8 = 'AX');
    s8 := REPLACE( IN1:= 'ABCDE', IN2 := 'X', L := 5 , P :=1 ); 
    _GEB_ASSERT_(s8 = 'X');
    s8 := REPLACE( IN1:= 'ABCDE', IN2 := 'X', L := 0 , P :=2 ); 
    _GEB_ASSERT_(s8 = 'AXBCDE');
    s8 := REPLACE( IN1:= 'ABC', IN2 := 'XY' , P :=2+1 ,L:=0 ); 
    _GEB_ASSERT_(s8 = 'ABXYC');

    s6 := INSERT( IN1:= 'ABC', IN2 := 'XY' , P :=2 ); 
    _GEB_ASSERT_(s6 = 'ABXYC');
    
    s5 := CONCAT( 'AB', 'CD' , 'E' ); 
    _GEB_ASSERT_(s5 = 'ABCDE');
    
    
    s7 := DELETE( IN:= 'ABXYC', L := 2 , P :=3 ); 
    _GEB_ASSERT_(s7 = 'ABC');
    i9 := FIND( IN1:= 'ABCBC', IN2 := 'BC');
    _GEB_ASSERT_(i9 = 2);
    ts1 := CONCAT('TS:' ,WORD_TO_STRING(i1 + 10));
    _GEB_ASSERT_(ts1 = 'TS:0x11');
    ts2 := BOOL_TO_STRING(1);
    _GEB_ASSERT_(ts2 = '1');
    ts3 := TIME_TO_STRING(TIME#10h);
    _GEB_ASSERT_(ts3 = 'T#10h00m00s000ms');
    u1 := 'a$$b'; // a$b
    _GEB_ASSERT_(LEN(u1) = 3);
    u1 := '$$'; 
    _GEB_ASSERT_(LEN(u1) = 1);
    
    u1 := 'A$'=$$=$C4Z"\';    //  A'=$=ÄZ"\   
    _GEB_ASSERT_(LEN(u1)=9);
    
    u2 := 'é UTF-8'; // this is UTF-8 (source) coded!   
    _GEB_ASSERT_(u2 = 'é UTF-8');
    _GEB_ASSERT_(LEN(u2) = 7);
    b1 := s2 = 'ASTR';  

    
    _GEB_ASSERT_(fb.so = '?');
    fb(I1 := 27 , si := 'Hi');
    _GEB_ASSERT_(fb.O1 = 427);
    _GEB_ASSERT_(fb.so = 'Hi400YES');
    fb(I1 := 1 , si := 'Bye');
    _GEB_ASSERT_(fb.so = 'Bye401NO');
    fb(I1 := 1 );
    _GEB_ASSERT_(fb.so = 'Bye402YES'); (* this could be undefined behaviour *) 


END_PROGRAM


(* 
   Function block with strings
   CONT starts at 400, increments by 1 at the end of each execution
   sx toggles at the end of each execution between YES and NO  (YES during first execution)
   O1 := I1 + CONT 
   so := CONCAT(si,INT_TO_STRING(CONT),sx);  
*)
FUNCTION_BLOCK FB3
VAR_INPUT I1 : INT; si:STRING; END_VAR
VAR CONT : INT := 400; 
sx : STRING := 'YES'; 
END_VAR 
VAR_OUTPUT      
O1 : INT; 
so: STRING := '?' ; 
END_VAR
  O1 := I1 + CONT;
  so := CONCAT(CONCAT(si,INT_TO_STRING(CONT)),sx);  
  CONT := CONT+1;
  IF sx = 'YES' THEN
  sx := 'NO';
  ELSE
  sx := 'YES';
  END_IF;

END_FUNCTION_BLOCK