参数数组提供了对一类参数集中存放的机制,其中LR内置的几个函数有:lr_paramarr_idx()、lr_paramarr_len()、lr_paramarr_random()
同时参数数组必须满足一下两个条件:①参数必须都是以相同的名字开头的,后接下划线加数字的方式顺序赋值;②参数数组必须要有一个“参数名_count”的参数来记录数字的长度。
eg:
lr_save_string(“www.google.com”,“website_1”);
lr_save_string(“www.baidu.com”,“website_2”);
lr_save_string(“www.163.com”,“website_3”);
lr_save_string(“www.sina.com.cn”,“website_4”);
lr_save_string(“4”,“website_count”);
通过这个脚本创建名为website的参数数组,接下来结合函数对该参数数组进行操作:
char *siteval;
siteval=lr_paramarr_idx("website",2) ----------输出:www.baidu.com
char *siteval
siteval=lr_paramarr_random(“website”)---------输出:website参数数组中的随机值
如果需要便利整个参数数组中的所有内容,可通过下面的方法实现:
int arrid
for(arrid=1;arrid<=lr_paramarr_len(“website”);i++)
{
lr_output_message(lr_paramarr_idx("website",arrid));
}
以下是帮助手册中的例子:
This example shows how to get the last value from a parameter array.
int arrSize;
char * FlightVal;
web_reg_save_param("outFlightVal",
"LB=outboundFlight value=", "RB=>",
"ORD=ALL",
"SaveLen=18",
LAST );
web_submit_form("reservations.pl",
"Snapshot=t4.inf",
ITEMDATA,
"Name=depart", "Value=London", ENDITEM,
"Name=departDate", "Value=11/20/2003", ENDITEM,
"Name=arrive", "Value=New York", ENDITEM,
"Name=returnDate", "Value=11/21/2003", ENDITEM,
"Name=numPassengers", "Value=1", ENDITEM,
"Name=roundtrip", "Value=<OFF>", ENDITEM,
"Name=seatPref", "Value=None", ENDITEM,
"Name=seatType", "Value=Coach", ENDITEM,
"Name=findFlights.x", "Value=83", ENDITEM,
"Name=findFlights.y", "Value=16", ENDITEM,
LAST );
/*
The result of the web_reg_save_param having been called before the web_submit_form is:
Notify: Saving Parameter "outFlightVal_1 = 230;378;11/20/2003"
Notify: Saving Parameter "outFlightVal_2 = 231;337;11/20/2003"
Notify: Saving Parameter "outFlightVal_3 = 232;357;11/20/2003"
Notify: Saving Parameter "outFlightVal_4 = 233;309;11/20/2003"
Notify: Saving Parameter "outFlightVal_count = 4"
*/
arrSize = lr_paramarr_len("outFlightVal");
FlightVal = lr_paramarr_idx("outFlightVal", arrSize);
// FlightVal contains the value "233;309;11/20/2003".