LoadRunner字符串与参数的操作及转换技巧

发表于:2007-12-18 16:43

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:ppent    来源:ppent 的博客

        刚开始学LR时,经常搞不清楚变量和参数的区别与用法,最近在一次脚本编写中,整理出来的一些小技巧,与大家一起分享。

//字符串复制
strcpy(str,"Hello ") ;

//字符串连接
strcat(str,"World !");
lr_message("str: %s",str);


//变量转为参数,将变量str的值存到参数Param中
lr_save_string(str,"Param");


//参数复制
lr_save_string(lr_eval_string("{Param}"),"Param_1");

 

//参数转为变量
strcpy(str1,lr_eval_string("{Param_1}"));
lr_message("str1: %s",str1);


//参数名称格式化输出到变量中
sprintf(str2,"{Param_%d}",1);
lr_message("str2: %s",lr_eval_string(str2));


运行结果:
str: Hello World !
vuser_init.c(14): Notify: Saving Parameter "Param = Hello World !"
vuser_init.c(19): Notify: Parameter Substitution: parameter "Param" =  "Hello World !"
vuser_init.c(19): Notify: Saving Parameter "Param_1 = Hello World !"
vuser_init.c(24): Notify: Parameter Substitution: parameter "Param_1" =  "Hello World !"
str1: Hello World !
vuser_init.c(30): Notify: Parameter Substitution: parameter "Param_1" =  "Hello World !"
str2: Hello World !

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号