个人网站: www.7dtest.com 7点测试群:(61369656)------(77273408)------(35710365)------(9410090)

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

上一篇 / 下一篇  2007-04-02 19:35:45 / 个人分类:Zee的生活


一:

以下脚本,定义两个一样的字符数组,对比后,打印出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...


TAG: Zee的生活

如果Zee还在工作 引用 删除 Zee   /   2007-04-26 18:15:07
谢谢提醒,是我输入有误。
hukx的个人空间 引用 删除 hukx   /   2007-04-26 08:59:21
3
脚本二的这里:
result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string1}"));  

你应该是string1和string2对比吧!你写成string1和string1对比咯,可能是输入时打错拉!

不过结果都是一样的啊!哈哈!
 

评分:0

我来说两句

我的栏目

日历

« 2024-05-10  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 159032
  • 日志数: 146
  • 图片数: 1
  • 建立时间: 2006-12-05
  • 更新时间: 2012-11-16

RSS订阅

Open Toolbar