【软件测试自动化-QTP NOTE 3】 ==VBScript 1st==

VBScript是QTP中默认的编辑脚本语言,所以VBS的脚本能力直接会影响到你的QTP水平。

这篇就大致罗列下QTP中会经常使用到的VBS函数及逻辑

 

1.Strings

  • Cint 返回整型

Dim x x=Cint("1.333") Msgbox x 

  • Cstr 返回字符串
  • Len 返回String长度

x=Len("hello world") Msgbox x 返回值 11 

  • Right/Left 从左/右的多少位字母

x=Left("hello world",5) Msgbox x 返回值 hello x=Right("hello world",5) Msgbox x 返回值 world 

  • Mid 定位字符起始,结束位置 返回字符

x=Mid("hello world",5,3) Msgbox x 返回值 o w  

  • Replace 字符替代

x=Replace("Hello world","world","earth") Msgbox x 返回 Hello earth  

  • Split 分割string

s_test="VBScriptXisXfun" x=split(s_test,"x",-1,1) Msgbox x(0) 返回VBScript Msgbox x(1) 返回is Msgbox x(2) 返回fun 

 

2.时间

  • Date 返回日期

x=Date() Msgbox x 

  • Time 返回时间

x=Time() Msgbox x 

  • Now 返回当前时间

x=Now() Msgbox x 

  • Day/Month/Year 返回日/月/年

s_day = Day("3/28/2010") Msgbox s_day s_month = Month("3/28/2010") Msgbox s_month s_year = Year("3/28/2010") '这里日期的格式可以随意 3/28/2010,3-28-2010,28/3/2010都会返回正确的值 

 

 


 

 

你可能感兴趣的:(Date,String,软件测试,脚本,VBScript,2010)