Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ InTouch HMI

StringToIntg() 函数

  • Last UpdatedJan 15, 2020
  • 1 minute read

在脚本中,通过使用 StringToIntg() 函数可以将字符串中包含的值转换为整数值。

您可以用它将字符串开头的值读取到整型标记,以便进行进一步的数学运算。

语法

result = StringToIntg (string)

参数

string

字符串、消息标记名或字符串表达式。

附注

此函数检查字符串的第一个字符。如果是数字,则它会试图将这个字符以及后续的字符读取到一个整数中,直至遇到非数值字符。此函数忽略字符串中的前导空格。

示例

StringToIntg(“ABCD”) 返回 0。

StringToIntg(“13.4 mbar”) 返回 13。

StringToIntg("Pressure is 13.4") 返回 0。

要从字符串 (mtag) 中提取不在开头位置的第一个整数并将它存储在整型标记 itag 中,请使用以下动作脚本:

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;

In This Topic
Related Links