StringToIntg() Function
- Last UpdatedFeb 19, 2019
- 1 minute read
In a script, you can convert a value contained in a string to an integer value by using the StringToIntg() function.
You can use this to read a value contained at the beginning of a string into an integer tag for further mathematical operations.
Syntax
result = StringToIntg (string)
Parameters
string
A literal string, message tagname, or string expression.
Remarks
The function checks the first character of the string. If it is a number, it attempts to read this and the following characters as an integer number until a non-numeric character is met. The function ignores leading spaces in the string.
Example(s)
StringToIntg("ABCD") returns 0.
StringToIntg("13.4 mbar") returns 13.
StringToIntg("Pressure is 13.4") returns 0.
To extract the first integer from a string (mtag) that is not at the beginning and to store it in the integer tag itag, use the following action script:
DIM i AS INTEGER;
DIM tmp AS INTEGER;
FOR i = 1 TO StringLen(mtag) {run variable i over the characters of mtag}
tmp = StringASCII(StringMid(mtag, i, 1)) - 48; {detect ASCII value}
IF (tmp>=0 AND tmp<10) THEN {if ASCII value represented "0" - "9"}
itag = StringToIntg(StringMid(mtag, i, 0)); {set itag to value from that position and exit loop}
EXIT FOR;
ENDIF;
NEXT;