Zee的LR脚本练习三:比较两个字符串变量

本文通过两个示例展示了如何使用LoadRunner进行字符串比较操作。第一个示例直接定义了两个字符串并进行了比较;第二个示例则使用LoadRunner API保存和加载字符串后再进行比较。两个示例均验证了相同字符串之间的正确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一:

以下脚本,定义两个一样的字符数组,对比后,打印出result的值:

vuser_init()
{

int result;
     char string1[] = "We can see the string:zee";
     char string2[] = "We can see the string:zee";
lr_output_message("the string1 is %s.",string1);
lr_output_message("the string2 is %s.",string2);

result = strcmp(string1,string2); 
   if ( result == 0 )
           {
        lr_output_message("the result is 0.");
        }
   else
   {
     lr_output_message("the result is not 0.");
   }

        return 0;
}

运行结果:

Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788          [MsgId: MMSG-27143]
Run-Time Settings file: "C:/Documents and Settings/Zee/Local Settings/Temp/noname26//default.cfg"          [MsgId: MMSG-27141]
vuser_init.c(7): the string1 is We can see the string:zee.
vuser_init.c(8): the string2 is We can see the string:zee.
vuser_init.c(13): the result is 0.
Ending action vuser_init.
Running Vuser...

 

二:

脚本:
vuser_init()
{

int result;
char string1;
char string2;
     lr_save_string( "We can see the string:zee","string1" );
     lr_save_string( "We can see the string:zee","string2" );

lr_output_message("the string1 is %s.",lr_eval_string("{string1}"));
lr_output_message("the string2 is %s.",lr_eval_string("{string2}"));

result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string1}")); 
   if ( result == 0 )
           {
        lr_output_message("the result is 0.");
        }
   else
   {
     lr_output_message("the result is not 0.");
   }

        return 0;
}

结果:

Starting action vuser_init.
Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788          [MsgId: MMSG-27143]
Run-Time Settings file: "C:/Documents and Settings/Zee/Local Settings/Temp/noname26//default.cfg"          [MsgId: MMSG-27141]
vuser_init.c(10): the string1 is We can see the string:zee.
vuser_init.c(11): the string2 is We can see the string:zee.
vuser_init.c(16): the result is 0.
Ending action vuser_init.
Running Vuser... 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值