【转】loadrunner字符串处理函数

在Loadrunner中提供了C对字符串出了的相关功能函数,如下:

lr_save_datetime

把当前日期和时间保存到一个参数中

lr_save_int

把一个整数保存为参数

lr_save_searched_string

保存一个字符数组相对于字符串出现的部分。

lr_save_string

把一个字符串保存到参数中

lr_save_var

把字符串的一部分内容保存为参数

lr_eval_string

返回参数的实际内容或返回一个包含参数的字符串的实际内容

     下面我们将对这些函数作一一说明,并举例实践。

void lr_save_datetime(const char *format, int offset,const char *name);

参数解释:

format

所检索的日期/时间信息的格式

offset

当前日期和时间的偏移量, 采用形式有: DATE_NOW, TIME_NOW, ONE_DAY, ONE_HOUR, ONE_MIN. 例如: TIME_NOW + ONE_HOUR

name

保存的参数名称,用来存储日期/时间信息。

例子:

  
  
Action() { lr_save_datetime( " Tomorrow is %B %d %Y " , DATE_NOW + ONE_DAY, " next " ); lr_output_message(lr_eval_string( " {next} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(5): Tomorrow is 七月 06 2011
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_int ( int value, const char *param_name);

参数解释:

value

将要保存到参数得整数值

param_name

保存的参数名称

例子:

  
  
Action() { int num; num = 5 ; lr_save_int(num * 2 , " param1 " ); lr_output_message(lr_eval_string( " {param1} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(6): 10
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_searched_string (const char *buffer, longbuf_size, unsigned int occurrence, const char *search_string, intoffset, unsigned int string_len, const char *parm_name );

参数解释:

buffer

The STRING or CARRAY buffer, part of whose contents you want to save.

buf_size

The buffer size.

occurrence

The occurrence number of the search_string (0-based count). For example, if the search_string occurs three times, and you want the second occurrence, setoccurrence to 1.

search_string

The string to search for in the buffer.

offset

The number of characters to skip after the end of the search string occurrence.

string_len

The number of characters to save.

parm_name

Parameter name to be used in subsequent lr statements to refer to the saved information. Name is enclosed in double-quotes.

例子:

  
  
Action() { char cBuff[] = " abc Emma Woodhouse abc Elizabeth Bennet abc William Price " ; lr_save_searched_string(cBuff, strlen(cBuff), 2 , " abc " , // Search for third occurrence of "abc" 1 , // Skip the space after "abc" 4 , // Put the next four characters... " Fannys_brother " ); // ... in parameter Fannys_brother. lr_output_message( " %s " ,lr_eval_string( " Fannys_brother={Fannys_brother} " )); return 0 ; }

运行结果为:

Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(9): Fannys_brother=Will
Ending action Action.
Ending iteration 1.
Ending Vuser...

int lr_save_string (const char *param_value, const char *param_name);

int lr_save_var (const char *param_value, unsigned long constvalue_len, unsigned long const options, const char *param_name);

char *lr_eval_string (const char *instring);

     以上三个函数我们经常会用在一起。例如:

例子:

  
  
Action() { lr_save_string( " testaaaab " , " InName " ); lr_output_message( " %d " ,strlen( " {InName} " )); lr_output_message( " %d " ,strlen( " {InName} " ) - 1 ); lr_save_var( lr_eval_string( " {InName} " ), strlen( " {InName} " ) - 1 , 0 , " ShortName " ); lr_output_message( " %s " ,lr_eval_string( " ShortName={ShortName} " )); lr_output_message( " ShortName=%s " ,lr_eval_string( " {ShortName} " )); return 0 ; }

Starting iteration 1.
Starting action Action.
Action.c(5): 8
Action.c(6): 7
Action.c(9): ShortName=testaaa
Action.c(10): ShortName=testaaa
Ending action Action.
Ending iteration 1.

      *****注:在loadrunner中,字符串处理函数用的比较多,其用法也比较简单。多加以练习操作,在项目实践中可以很快的做到得心应手。*****

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值