(二十三)字符串方法
函数具体使用,在QTP帮助文档中查看
一、InStr函数
功能:Returns the position of the first occurrence of one string within another.
InStr([start, ]string1, string2[, compare])
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".
MyPos = Instr(1, SearchString, SearchChar) ' A binary comparison starting at position 1. Returns 9.
二、Mid函数
功能:Returns a specified number of characters from a string.
Mid(string, start[, length])
注意:可选的是长度,而不是截止下标
而且从1开始计数
Dim MyVar
MyVar = Mid("VB Script is fun!", 4, 6) ' MyVar contains "Script".
用Mid函数,$168.40的值
tarstr="$168.40"
Mid(tarstr,2)
三、Len函数
功能:Returns the number of characters in a string or the number of bytes required to store a variable.
Len(string | varname)
四、Left函数
功能:Returns a specified number of characters from the left side of a string.
Left(string, length)
Dim MyString, LeftString
MyString = "VBSCript"
LeftString = Left(MyString, 3) ' LeftString contains "VBS".
五、Right函数
功能:Returns a specified number of characters from the right side of a string.
Right(string, length)
tarstr="$168.40"
用right函数,得到价格值,价格长度不固定
Right(tarstr,len(tarstr)-1)