strGetValues (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


strGetValues will try to extract up to 4 values from a string. It uses the same syntax for the format string as strFormat. strGetValues is not case-sensitive.

 

 

Input:

str : STRING

String that strGetValues will extract values from.

 

format : STRING

The format string can contain up to 4 parameter references written as

\1, \2, \3 and \4. Each of these will extract the value at that position and place it in v1, v2, v3, or v4.

Please note that a specific number can only be referenced one time in the format string.

 

Please note that the 4th value is a DINT type, this allows you to convert large numbers.

 

Output:

match: BOOL

This will be TRUE if a match was found, and the number of values was extracted successfully

 

v1: INT

The extracted value at {1} from str

 

v2: INT

The extracted value at {2} from str

 

v3: INT

The extracted value at {3} from str

 

v4 : DINT

The extracted value at {4} from str

 

Declaration:

FUNCTION_BLOCK strGetValues;
VAR_INPUT
  str   : STRING;
  format : STRING;
END_VAR;
VAR_OUTPUT
  match : BOOL;
  v1     : INT;
  v2     : INT;
  v3     : INT;
  v4     : DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  extract     : strGetValues;
  inputstring : STRING;
END_VAR;
 
PROGRAM test;
 
BEGIN
  ...
  inputstring:="The temperature at sensor 12 is 32 degrees";
 extract(str:=inputstring, format:="The temperature at sensor \1 is \2 degrees");
  IF extract.match THEN
    // extract.v1 contains 12, extract.v2 contains 32
     ...
  END_IF;
END;
 
END_PROGRAM;