LR中用C语言比较两个字符串变量
2012-12-25 19:05
387 查看
一:
以下脚本,定义两个一样的字符数组,对比后,打印出result的值:
1. vuser_init()
2. {
3. int result;
4. char string1[] = "We can see the string:nancy";
5. char string2[] = "We can see the string:nancy";
6. lr_output_message("the string1 is %s.",string1);
7. lr_output_message("the string2 is %s.",string2);
8. result = strcmp(string1,string2);
9. if ( result == 0 )
10. {
11. lr_output_message("the result is 0.");
12. }
13. else
14. {
15. lr_output_message("the result is not 0.");
16. }
17. return 0;
18.}
复制代码
运行结果:
1. Starting action vuser_init.
2. Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788 [MsgId: MMSG-27143]
3. Run-Time Settings file: "C:\Documents and Settings\Zee\Local Settings\Temp\noname26\\default.cfg" [MsgId: MMSG-27141]
4. vuser_init.c(7): the string1 is We can see the string:nancy.
5. vuser_init.c(8): the string2 is We can see the string:nancy.
6. vuser_init.c(13): the result is 0.
7. Ending action vuser_init.
8. Running Vuser...
复制代码
二:
脚本:
1. vuser_init()
2. {
3. int result;
4. char string1;
5. char string2;
6. lr_save_string( "We can see the string:nancy","string1" );
7. lr_save_string( "We can see the string:nancy","string2" );
8. lr_output_message("the string1 is %s.",lr_eval_string("{string1}"));
9. lr_output_message("the string2 is %s.",lr_eval_string("{string2}"));
10.result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string2}"));
11. if ( result == 0 )
12. {
13. lr_output_message("the result is 0.");
14. }
15. else
16. {
17. lr_output_message("the result is not 0.");
18. }
19. return 0;
20.}
复制代码
结果:
1. Starting action vuser_init.
2. Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788 [MsgId: MMSG-27143]
3. Run-Time Settings file: "C:\Documents and Settings\Zee\Local Settings\Temp\noname26\\default.cfg" [MsgId: MMSG-27141]
4. vuser_init.c(10): the string1 is We can see the string:nancy.
5. vuser_init.c(11): the string2 is We can see the string:nancy.
6. vuser_init.c(16): the result is 0.
7. Ending action vuser_init.
8. Running Vuser...
复制代码
以下脚本,定义两个一样的字符数组,对比后,打印出result的值:
1. vuser_init()
2. {
3. int result;
4. char string1[] = "We can see the string:nancy";
5. char string2[] = "We can see the string:nancy";
6. lr_output_message("the string1 is %s.",string1);
7. lr_output_message("the string2 is %s.",string2);
8. result = strcmp(string1,string2);
9. if ( result == 0 )
10. {
11. lr_output_message("the result is 0.");
12. }
13. else
14. {
15. lr_output_message("the result is not 0.");
16. }
17. return 0;
18.}
复制代码
运行结果:
1. Starting action vuser_init.
2. Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788 [MsgId: MMSG-27143]
3. Run-Time Settings file: "C:\Documents and Settings\Zee\Local Settings\Temp\noname26\\default.cfg" [MsgId: MMSG-27141]
4. vuser_init.c(7): the string1 is We can see the string:nancy.
5. vuser_init.c(8): the string2 is We can see the string:nancy.
6. vuser_init.c(13): the result is 0.
7. Ending action vuser_init.
8. Running Vuser...
复制代码
二:
脚本:
1. vuser_init()
2. {
3. int result;
4. char string1;
5. char string2;
6. lr_save_string( "We can see the string:nancy","string1" );
7. lr_save_string( "We can see the string:nancy","string2" );
8. lr_output_message("the string1 is %s.",lr_eval_string("{string1}"));
9. lr_output_message("the string2 is %s.",lr_eval_string("{string2}"));
10.result = strcmp(lr_eval_string("{string1}"),lr_eval_string("{string2}"));
11. if ( result == 0 )
12. {
13. lr_output_message("the result is 0.");
14. }
15. else
16. {
17. lr_output_message("the result is not 0.");
18. }
19. return 0;
20.}
复制代码
结果:
1. Starting action vuser_init.
2. Web Turbo Replay of LoadRunner 8.1.0 for WINXP; Web build 4788 [MsgId: MMSG-27143]
3. Run-Time Settings file: "C:\Documents and Settings\Zee\Local Settings\Temp\noname26\\default.cfg" [MsgId: MMSG-27141]
4. vuser_init.c(10): the string1 is We can see the string:nancy.
5. vuser_init.c(11): the string2 is We can see the string:nancy.
6. vuser_init.c(16): the result is 0.
7. Ending action vuser_init.
8. Running Vuser...
复制代码
相关文章推荐
- Zee的LR脚本练习二:比较两个字符串变量
- Zee的LR脚本练习三:比较两个字符串变量
- 6-2-1 字符串-字符串变量String-创建字符串变量-初始化字符串变量-字符串连接-输入字符串(单词、行)-对象变量的赋值-比较两个字符串是否同一个-比较两个字符串内容是否相同
- C语言实现比较两个字符串的大小
- c语言比较两个字符串是否相等strcmp
- 在C语言中比较两个字符串是否相等的方法
- Java中,比较两个字符串引用变量是否相等
- c语言比较两个字符串是否相等strcmp
- 【C语言】模拟strcmp比较两个字符串
- 【c语言】将两个字符串s1和s2比较不要用strcmp
- C语言中比较两个字符串的大小
- (c语言)比较两个字符串的长度
- 比较两个字符串得到两个字符串的最大子串
- C的一些简单习题(5)--两个字符串比较
- 2015大众点评校园招聘笔试题——比较两个字符串的相同部分和不同部分
- c语言:4种方法;交换两个整数的位置(包括引入第三方变量和不引入第三方变量)
- lr中定义字符串变量
- Java实现两个字符串的比较
- scanf( )和gets如何用C语言从键盘上输入并打印一串字符串的比较
- PHP 比较两个字符串的相似度