Is the format of the real values always 3 decimal digits, a period, 2 fraction digits and a comma ?
If that is the case you can 'simply' extract every character one by one.
something like this:
This is just a rough code idea. Not tested !
Not sure if I got the character count right, but you get the idea.
If that is the case you can 'simply' extract every character one by one.
something like this:
Code:
FUNCTION_BLOCK "FB_SPLITREALSTRING"
VAR
sourcestr : STRING[72] ; //:= '123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45,123.45' ;
sourcestr_chars AT sourcestr : ARRAY[0..73] OF CHAR ;
strTable : ARRAY[0..11] OF STRING[7] ;
strTable_chars AT strTable : ARRAY[0..107] OF CHAR ;
i : INT ;
END_VAR
LABEL
ERROR, NORMALEXIT ;
END_LABEL ;
FOR i:= 0 TO 11 BY 1 DO
IF NOT (sourcestr_chars[i*7 + 5] = '.') OR NOT (sourcestr_chars[i*7 + 8] = ',') THEN
GOTO ERROR ;
END_IF ;
strTable_chars[i*9 + 2] := sourcestr_chars[i*7 + 2];
strTable_chars[i*9 + 3] := sourcestr_chars[i*7 + 3];
strTable_chars[i*9 + 4] := sourcestr_chars[i*7 + 4];
strTable_chars[i*9 + 5] := '.';
strTable_chars[i*9 + 6] := sourcestr_chars[i*7 + 6];
strTable_chars[i*9 + 7] := sourcestr_chars[i*7 + 7];
strTable_chars[i*9 + 8] := ',';
END_FOR ;
GOTO NORMALEXIT ;
ERROR: ;
NORMALEXIT: ;
END_FUNCTION_BLOCK
Not sure if I got the character count right, but you get the idea.
Last edited: