一、lr_save_string函数

1.该函数主要是将程序中的常量或变量保存为参数;

  1. //将常量保存为参数
  2. lr_save_string("777","page");
  3. web_url(http://www.sina.com.cn/{page});
  4. lr_eval_string("{page}");
  5.  
  6. //将变量保存为参数,tmp为变量
  7. lr_save_string(tmp,"page");
  8. web_url(http://www.sina.com.cn/{page});
  9. lr_eval_string("{page}");

  

二、sprintf函数

定义函数 int sprintf( char *str,const char * format,.........);
函数说明     sprintf()会根据参数format字符串来转换并格式化数据,然后将结果复制到参数str所指的字符串数组,直到出现字符串结束(’\0’)为止。关于参数format字符串的格式请参考printf()。
返回值 成功则返回参数str字符串长度,失败则返回-1,错误原因存于errno中。
附件说明 使用此函数得留意堆栈溢出,或改用snprintf()。
示例 #include<stdio.h>
main()
{
char * a=”This is string A!”;
char buf[80];
sprintf(buf,”>>> %s<<<\n”,a);
printf(“%s”.buf);
}
执行 >>>This is string A!<<<
  1. 常用该函数代替itoa,将整数格式化为字符串形式。
  2. 例如:
  3. int page=0;
  4. char page_ch[60];
  5. page=page + 10;
  6. sprintf(page_ch,"%d",page);

  

三、lr_eval_string函数

用于返回instring参数中的实际字符串值,可以使用该函数来查看参数化取值是否正确;

  1. char *tmp="hello";
  2. lr_save_string("777","page"); //将常量777保存为参数page
  3. lr_output_message(lr_eval_string("{page}")); //获取并输出参数page的当前值
  4. lr_save_string(tmp,"page"); //将变量保存为参数,tmp为变量
  5.  
  6. lr_output_message(lr_eval_string("{page}"));

脚本示例:

  1. example:
  2. int count;
  3. web_reg_save_param("flight_num",
  4. "LB=新",
  5. "RB=闻",
  6. "ORD=All",
  7. LAST);
  8. count=atoi(lr_eval_string("{flight_num_count}"));
  9.  
  10. //sprintf
  11.  
  12. The following example uses sprintf to write the name of a file to a string buffer,
  13. filename. This name is made up of the word "log", an underscore, the value of i, and the
  14. file suffix.
  15.  
  16. example:
  17. Action()
  18. {
  19. int index = 56;
  20. char filename[64], *suffix = "txt";
  21.  
  22. sprintf(filename, "log_%d.%s", index, suffix);
  23. lr_output_message("The new file name is %s", filename);
  24.  
  25. return 0;
  26. }
  27. Output:
  28. Action.c(9): The new file name is log_56.txt
  29.  
  30. //
  31. lr_save_string
  32.  
  33. Saves a null-terminated string to a parameter.
  34.  
  35. int lr_save_string (const char *param_value, const char *param_name);
  36.  
  37. aram_value The value to assign to the parameter.
  38. param_name The name of the parameter.
  39.  
  40. The lr_save_string function assigns the specified null-terminated string to a parameter.
  41. This function is useful in correlating queries. To determine the value of the parameter,
  42. use the lr_eval_string function.
  43.  
  44. example:
  45. lr_save_string("777", "emp_id");
  46.  
  47. ///
  48. #include "as_web.h"
  49.  
  50. Action()
  51. {
  52.  
  53. int i;
  54. int count;
  55. char param[10][20];
  56.  
  57. web_reg_save_param("flight_num",
  58. "LB=新",
  59. "RB=闻",
  60. "ORD=All",
  61. LAST);
  62.  
  63. web_add_cookie("BAIDUID=643CC8042E92F7FB5EF83827498BDBDC:FG=1; DOMAIN=www.baidu.com");
  64.  
  65. web_add_cookie("BDSTAT=495409234680ac099258d109b3de9c82d158ccbf6f81800a19d8bc3eb035a10e;
  66. DOMAIN=www.baidu.com");
  67.  
  68. web_add_header("Accept-Language",
  69. "zh-cn");
  70.  
  71. web_url("www.baidu.com",
  72. "URL=http://www.baidu.com/",
  73. "Resource=0",
  74. "RecContentType=text/html",
  75. "Referer=",
  76. "Snapshot=t1.inf",
  77. "Mode=HTML",
  78. LAST);
  79.  
  80. count=atoi(lr_eval_string("{flight_num_count}"));
  81. lr_error_message("已经数量:%d",count);
  82. for(i=1;i<=count;i++)
  83. {
  84. sprintf(param[i],"{flight_num_%d}",count);
  85. lr_error_message(param[i]);
  86. }
  87. for(i=1;i<count;i++)
  88. {
  89. lr_error_message(lr_eval_string(param[i]));
  90. }
  91.  
  92. return 0;
  93. }

  

lr_save_string和sprintf、lr_eval_string的使用的更多相关文章

  1. 转:lr_eval_string,lr_save_string 和 sprintf 的使用

    lr_eval_string,lr_save_string和 sprintf 函数使用介绍 一.lr_eval_string 使用介绍1.函数的主要作用:返回脚本中的一个参数当前的值,返回值类型:ch ...

  2. lr_save_string 和 sprintf 的使用

    lr_save_string 和 sprintf 的使用 一.lr_save_string 使用介绍1.该函数主要是将程序中的常量或变量保存为lr中的参数.格式: //将常量保存为参数 lr_save ...

  3. LoadRunner lr_eval_string() 函数使用及LR中变量、参数的简单使用

    lr_eval_string() 函数的主要作用:返回脚本中的一个参数当前的值, 返回值类型:char 一般多用在调试脚本时输出参数的值.具体用法如下:lr_output_message(" ...

  4. lr函数之lr_eval_string()函数的使用学习

    lr_eval_string() 函数的主要作用:返回脚本中的一个参数当前的值(从参数中取得对应的值,并且转换为一个字符串). 格式:lr_eval_string("{参数名}") ...

  5. 使用loadrunner进行压力测试之----post请求

    1. 发送post请求时使用web_submit_data 如: web_submit_data("create",//事务名 "Action=http://bizhi. ...

  6. Loadrunner中参数和变量的使用

    //字符串复制strcpy(str,"Hello ") ; //字符串连接strcat(str,"World !");lr_message("str: ...

  7. Loadrunner脚本编程(1)-大体思路

    http://www.360doc.com/content/10/0806/13/1698198_44076570.shtml 就目前的了解.Loadrunner的脚本语言其实和C没什么区别.他内部的 ...

  8. Loadrunner C 编程_1

    就目前的了解.Loadrunner的脚本语言其实和C没什么区别.他内部的好多机制都是C实现的. 不过是一种“类C” 所以我从几个方面分析 1:定义常量变量和C一样 2:在LR中,C的变量和LR的参数是 ...

  9. LR参数和变量

    一.参数: 1. 在LR函数中可以直接使用参数.参数必须在双引号“”中才能应用.大部分情况下,可以直接用参数代替函数中双引号内的数据.如下使用方法: lr_save_string("http ...

随机推荐

  1. PropertyUtilsBean 将bean转成map

    public static Map<String,String> beanToMap(Object bean) { Map<String,String> params =Map ...

  2. RabbitMQ入门教程(八):远程过程调用RPC

    原文:RabbitMQ入门教程(八):远程过程调用RPC 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.cs ...

  3. 07.AutoMapper 之列表和数组(Lists and Arrays)

    https://www.jianshu.com/p/419a3b7f12d5 列表和数组(Lists and Arrays) AutoMapper只需要配置元素类型的映射配置,不需要针对列表和数组进行 ...

  4. java中的进制转换

    java中的进制转换及转换函数 转自:https://blog.csdn.net/V0218/article/details/74945203 Java的进制转换 进制转换原理 十进制 转 二进制: ...

  5. HTTP,FTP异常码大全【转载】

    HTTP 400 - 请求无效HTTP 401.1 - 未授权:登录失败HTTP 401.2 - 未授权:服务器配置问题导致登录失败HTTP 401.3 - ACL 禁止访问资源HTTP 401.4 ...

  6. ConditionalOnProperty的使用

    时间  2018-02-23 标签 ConditionalOnPropert SpringBoot 栏目 Spring 原文   http://blog.csdn.net/u010002184/art ...

  7. 索引介绍,转载自:https://tech.meituan.com/2014/06/30/mysql-index.html

    索引原理 除了词典,生活中随处可见索引的例子,如火车站的车次表.图书的目录等.它们的原理都是一样的,通过不断的缩小想要获得数据的范围来筛选出最终想要的结果,同时把随机的事件变成顺序的事件,也就是我们总 ...

  8. 【HDU3308】LCIS

    题目大意:维护一个长度为 N 的序列,支持单点修改,区间查询最长连续上升子序列的长度. 题解: 线段树维护一段区间左端点开始的 LCIS 长度,右端点开始的 LCIS 长度以及区间最优解.考虑进行合并 ...

  9. Java注解Annotation与自定义注解详解

    Java注解简介 开发中经常使用到注解,在项目中也偶尔会见到过自定义注解,今天就来探讨一下这个注解是什么鬼,以及注解的应用场景和如何自定义注解. 下面列举开发中常见的注解 @Override:用于标识 ...

  10. ZROI 19.07.30 简单字符串/ll

    写在前面:今天下午药丸--不会字符串,全程掉线/ll 给出字符串\(S\),\(q\)次询问,每次给出\(a,b,c,d\),询问\(S[a,b]\)的所有子串和\(S[c,d]\)最长公共前缀的最大 ...