QTP中几个截取字符串的函数

  Left 函数(Right函数就是从右边开始算起)
}/^Az'|:M t6H${120659返回指定数目的从字符串的左边算起的字符。Left(string, length) 软件测试专业网站:51Testing软件测试网)Z.`O-[8f
参数 软件测试专业网站:51Testing软件测试网 gD0|h,[$lt
string:字符串表达式,其最左边的字符被返回。如果 string 参数中包含 Null,则返回 Null。
*A8XZKi!uV120659Length:数值表达式,指明要返回的字符数目。如果是 0,返回零长度字符串 ("");如果大于或等于 string 参数中的字符总数,则返回整个字符串。
+o%Y)t1eLY)z120659例子:
OpXP7\kp.o120659Dim MyString, LeftString
&YCb*W8mPp120659MyString = "VBscrīpt"
)f(O1@9K%LY120659LeftString = Left(MyString, 3) ' LeftString contains "VBS".
(~x7ryR*}120659*********************************** 软件测试专业网站:51Testing软件测试网 S$~5M/R6w#gd-w
Mid 函数
'} |,njU-h6MKQ120659从字符串中返回指定数目的字符。 软件测试专业网站:51Testing软件测试网 r*Aw]&b+d3P
Mid(string, start[, length]) 软件测试专业网站:51Testing软件测试网(_:dC.uy(h~
参数:
r"HLst3L120659string:字符串表达式,从中返回字符。如果 string 包含 Null,则返回 Null。
Z0D%kIM120659Start:string 中被提取的字符部分的开始位置。如果 start 超过了 string 中字符的数目,Mid 将返回零长度字符串 ("")。 软件测试专业网站:51Testing软件测试网#U"fE$?Cq;GAn \"}S
Length:要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到字符串结束的所有字符。 软件测试专业网站:51Testing软件测试网BZOK%sz.U)`~
例子
in7{]3z&P g9KU120659Dim MyVar 软件测试专业网站:51Testing软件测试网UQ@SW%?-W9F
MyVar = Mid("VB scrīpt is fun!", 4, 6) ' MyVar contains "scrīpt". 软件测试专业网站:51Testing软件测试网K^/b[ Z[
********************
!c7r-x%\ m$qo,c120659 InStr函数(InStrRev函数相反从最后向前起) 软件测试专业网站:51Testing软件测试网} BQ)n%C }
返回指定的字符串在另一字符串中最先出现的位置。 软件测试专业网站:51Testing软件测试网:s6|0a*f+?VE.Lm
InStr([start, ]string1, string2[, compare])
3{e;wXL#l0H(M'_5Pow120659参数: 软件测试专业网站:51Testing软件测试网 w,x|/uZWl M
start:起始位置,默认从第一位 软件测试专业网站:51Testing软件测试网h|"\ es*o |3_2Z
string1:主体字符串,从左向右查找。如果string1为 Null,则返回 Null。
pUd6Lke^ y120659string2:查找的字符串,如果string2为 Null,则返回 Null。找不到就返回0。
M A)qZ`&t l ^\2p120659compare:0是二进制比较,1是文本比较。0为缺省值。个人 感觉区别就是在大小写。 软件测试专业网站:51Testing软件测试网Sf(k/? \
例子
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP"   
' String to search in.
SearchChar = "P" 
  ' Search for "P".
MyPos = Instr(4, SearchString, SearchChar, 1) 
  ' A textual comparison starting at position 4. Returns 6.
  msgbox MyPos
MyPos = Instr(1, SearchString, SearchChar, 0)
  ' A binary comparison starting at position 1. Returns 9.   
    msgbox MyPos
MyPos = Instr(SearchString, SearchChar)
  ' Comparison is binary by default (last argument is omitted). Returns 9
    msgbox MyPos
MyPos = Instr(1, SearchString, "W")   
' A binary comparison starting at position 1. Returns 0 ("W" is not found).
  msgbox MyPos

Split 函数软件测试专业网站:51Testing软件测试网H(nm/I(r/NAI
在指定的 delimiter 参数出现的所有位置断开 String 对象,将其拆分为子字符串,然后以数组形式返回子字符串。
Q+GB,RA4hYb(~ j120659Split(expression[, delimiter[, count[, compare]]])
-z fOnLGF0\J120659参数 软件测试专业网站:51Testing软件测试网9Z2tE#s+tv$G!n l5wM"I
expression:主体字符串,也就是要被拆分处的字符或字符串。
LM ^oz&R L+~n120659delimiter:拆分元素,默认是(" ")
&f.@C~6ht!H_120659count:Number [可选] 要放入数组中的项目数。 软件测试专业网站:51Testing软件测试网$}sSMTm`2U1g[
compare:0是二进制比较,1是文本比较。0为缺省值。
a tB'N`-w%Y120659例子
Dim MyString, MyArray, Msg
MyString = "VBscrīptXisXfun!"
MyArray = Split(MyString, "x", -1, 1)
' MyArray(0) contains "VBscrīpt"
' MyArray(1) contains "is"
' MyArray(2) contains "fun!".
Msg = MyArray(0) & " " & MyArray(1)& " " & MyArray(2)
MsgBox Msg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值