lr_eval_string;sprintf;lr_save_string;用法

一、lr_save_string 使用介紹
1.該函數主要是將程序中的常量或變量保存爲lr中的參數。
格式:

//將常量保存爲參數
lr_save_string("777","page");
web_url(http://www.sina.com.cn/{page});
lr_eval_string("{page}");
//將變量保存爲參數,tmp爲變量
lr_save_string(tmp,"page");
web_url(http://www.sina.com.cn/{page});
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!<<<

常用該函數代替itoa,將整數格式化爲字符串形式。
如:

int page=0;
char page_ch[56];
page=page + 10;
sprintf(page_ch,"%d",page);

 

 

 

lr_eval_string

用於返回instring參數中的實際字符串值,可以使用該函數來查看參數化取值是否正確

example:
int count;
web_reg_save_param("flight_num",
"LB=新",
"RB=聞",
"ORD=All",
LAST);
count=atoi(lr_eval_string("{flight_num_count}"));

//sprintf

The following example uses sprintf to write the name of a file to a string buffer, filename. This name is made up of the word "log", an underscore, the value of i, and the file suffix.
example:
Action()
{
int index = 56;
char filename[64], *suffix = "txt";

sprintf(filename, "log_%d.%s", index, suffix);
lr_output_message("The new file name is %s", filename);

return 0;
}
Output:
Action.c(9): The new file name is log_56.txt
//
lr_save_string


Saves a null-terminated string to a parameter.

int lr_save_string (const char *param_value, const char *param_name);

aram_value The value to assign to the parameter.
param_name The name of the parameter.


The lr_save_string function assigns the specified null-terminated string to a parameter. This function is useful in correlating queries. To determine the value of the parameter, use the lr_eval_string function.

example:
lr_save_string("777", "emp_id");

///
#include "as_web.h"


Action()
{

int i;
int count;
char param[10][20];

web_reg_save_param("flight_num",
"LB=新",
"RB=聞",
"ORD=All",
LAST);

web_add_cookie("BAIDUID=643CC8042E92F7FB5EF83827498BDBDC:FG=1; DOMAIN=www.baidu.com");

web_add_cookie("BDSTAT=495409234680ac099258d109b3de9c82d158ccbf6f81800a19d8bc3eb035a10e; DOMAIN=www.baidu.com");

web_add_header("Accept-Language",
"zh-cn");

web_url("www.baidu.com",
"URL=http://www.baidu.com/",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
LAST);

count=atoi(lr_eval_string("{flight_num_count}"));
lr_error_message("已經數量:%d",count);
for(i=1;i<=count;i++)
{
sprintf(param[i],"{flight_num_%d}",count);
lr_error_message(param[i]);
}
for(i=1;i<count;i++)
{
lr_error_message(lr_eval_string(param[i]));
}


return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章