strFormat (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


strFormat is used to format a string. By supplying the function with a format string, a string, and up to 4 numbers, it is possible to format a string.

The format string can be specified such that up to 4 numbers can be inserted in a string. Please look at the examples below.

 

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

 

Note that the returned string is a dynamic string.

 

Input:

format : STRING

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

\1, \2, \3 and \4. Each of these will insert the value in v1, v2, v3, and v4.

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

 

v1 : INT

Value for {1} in the format string.

 

v2 : INT

Value for {2} in the format string.

 

v3 : INT

Value for {3} in the format string.

 

v4 : DINT

Value for {4} in the format string.

 

Returns: STRING

A string containing the resulting string from the formatting

 

Declaration:

FUNCTION strFormat : STRING;
VAR_INPUT
  format   : STRING;
  v1,v2,v3 : INT;
  v4       : DINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  number1 : INT;
  number2 : INT;
  str     : STRING;
END_VAR;
 
PROGRAM test;
 
BEGIN
  ...
  str := strFormat(format:="The temperature at sensor \1 is \2 degrees", v1:=12, v2:=32);
  // str will now contain: "The temperature at sensor 12 is 32 degrees"
  ...
  str := strFormat(format:="\1", v1 := 4711);
  // str will now contain: "4711"
  ...
END;
 
END_PROGRAM;