不谋万世者,不足谋一时;不谋全局者,不足谋一域。君子敏于事而慎于言 新浪微薄:土司阿哈

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

上一篇 / 下一篇  2008-04-15 21:38:14

51Testing软件测试网*vJ$em S!az5W O!l GbT

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

%MI(QL)g)UO0

d2X u!a"X0 51Testing软件测试网z;`*?:H1hU@&S

51Testing软件测试网-{3] {5q%q5j ?M\U

Left 函数(Right函数就是从右边开始算起)
*YBi@%v.q0返回指定数目的从字符串的左边算起的字符。Left(string, length)51Testing软件测试网]1YQBiX~l$j
参数
5U3a(cY!J\0string:字符串表达式,其最左边的字符被返回。如果 string 参数中包含 Null,则返回 Null。
Y I n0Ej`V/eK0Length:数值表达式,指明要返回的字符数目。如果是 0,返回零长度字符串 ("");如果大于或等于 string 参数中的字符总数,则返回整个字符串。
0Q$j+z Dhb0例子:
k/Sz-W+K0Dim MyString, LeftString
P"oZy/e?0MyString = "VBscrīpt"51Testing软件测试网Ek7{|"Fpq
LeftString = Left(MyString, 3) ' LeftString contains "VBS".
PHrIV8s$M0***********************************
s-@:e(U"f0Mid 函数51Testing软件测试网"b$EAZJ2E{JQK"gPE
从字符串中返回指定数目的字符。
S w$m j Q4Jwt0Mid(string, start[, length])
_$B)ZG%]0参数:
_h*A3sX3j_ u0string:字符串表达式,从中返回字符。如果 string 包含 Null,则返回 Null。51Testing软件测试网;J/JLn/F7yi'g"u3U
Start:string 中被提取的字符部分的开始位置。如果 start 超过了 string 中字符的数目,Mid 将返回零长度字符串 ("")。51Testing软件测试网6U{IZ,aa7E-n&T b
Length:要返回的字符数。如果省略或 length 超过文本的字符数(包括 start 处的字符),将返回字符串中从 start 到字符串结束的所有字符。
4G kUQ0}0例子
&?!fu q"l%we-OcE8i%j0Dim MyVar
F`P3G:r5f-C \0MyVar = Mid("VB scrīpt is fun!", 4, 6) ' MyVar contains "scrīpt".51Testing软件测试网4Y`:m(m*]*F
********************51Testing软件测试网*]Hj+M7Bw
InStr函数(InStrRev函数相反从最后向前起)
oZM J(vpPY0返回指定的字符串在另一字符串中最先出现的位置。
R$^p#[]_ `gw1}0InStr([start, ]string1, string2[, compare])
*zFB8])Z8]0参数:
HR C8eXa}IUb0start:起始位置,默认从第一位51Testing软件测试网R cg5M/T/n*vTJ0A
string1:主体字符串,从左向右查找。如果string1为 Null,则返回 Null。51Testing软件测试网 oF6nWk gq
string2:查找的字符串,如果string2为 Null,则返回 Null。找不到就返回0。
!kV Dy9i:x z_9Z0compare:0是二进制比较,1是文本比较。0为缺省值。个人感觉区别就是在大小写。51Testing软件测试网%F6e*}%P%hq([D
例子51Testing软件测试网^oI~,n;f
Dim SearchString, SearchChar, MyPos51Testing软件测试网qhmP_8Y:I$Z6t$n
SearchString ="XXpXXpXXPXXP"   ' String to search in.51Testing软件测试网(@SR:w2o Zl]#g
SearchChar = "P"   ' Search for "P".51Testing软件测试网8K$r.s(hr[W
MyPos = Instr(4, SearchString, SearchChar, 1)   ' A textual comparison starting at position 4. Returns 6.51Testing软件测试网*J5Yp;r nvcr
MyPos = Instr(1, SearchString, SearchChar, 0)   ' A binary comparison starting at position 1. Returns 9.   51Testing软件测试网_r3{g,{Q G
MyPos = Instr(SearchString, SearchChar)   ' Comparison is binary by default (last argument is omitted). Returns 9.
W m x8b;Es KQ0S$X0MyPos = Instr(1, SearchString, "W")   ' A binary comparison starting at position 1. Returns 0 ("W" is not found).
g uaLe1e1Y0******************
0C,H;D~8t0Split 函数51Testing软件测试网gSf+Q&b m`
在指定的 delimiter 参数出现的所有位置断开 String 对象,将其拆分为子字符串,然后以数组形式返回子字符串。
8a2h1l"u&}{0Split(expression[, delimiter[, count[, compare]]])
kh'q&t:Mv|Y0参数51Testing软件测试网E{M&{/i'GiG2w
expression:主体字符串,也就是要被拆分处的字符或字符串。51Testing软件测试网}\)U8@/_
delimiter:拆分元素,默认是(" ")51Testing软件测试网B Q ~mi(e.]s
count:Number [可选] 要放入数组中的项目数。51Testing软件测试网{"bQ%az6A:}|
compare:0是二进制比较,1是文本比较。0为缺省值。
m:R QR$t[$n{0例子51Testing软件测试网Q7r Wc#TF@1~
Dim MyString, MyArray, Msg
oes W8c9WH z0MyString = "VBscrīptXisXfun!"
&F\o.v1q%T;t_0MyArray = Split(MyString, "x", -1, 1)
P-IGwj;Kgb I`0' MyArray(0) contains "VBscrīpt".51Testing软件测试网VN F,c~8d C A,U
' MyArray(1) contains "is".51Testing软件测试网\~9j{ nT { y
' MyArray(2) contains "fun!".51Testing软件测试网9G6mR*bGUA~IQ9]XK
Msg = MyArray(0) & " " & MyArray(1)
+?(b/Iw,LY[9z(o0Msg = Msg   & " " & MyArray(2)51Testing软件测试网!U!?"sD j)cN
MsgBox Msg

o/gzD!o2EFz.e;~0
%?e*?Y W+W0

7@GuLSf:Yn0


TAG:

 

评分:0

我来说两句

Open Toolbar