2 strchr
char *strchr ( const char *string, int c );
功能:返回字符串中指定字符后面的字符串。
例子:
这个例子是返回第一个出现e字符以后所有的字符,和最后一次出现e字符以后所有的字符。
脚本如下:
char *string = "Zee is a tester";
char *first_e, *last_e;
first_e = (char *)strchr(string, 'e');
lr_output_message("We can see the first occurrence of e: %s",first_e);
last_e = (char *)strrchr(string, 'e');
lr_output_message("We can see the last occurrence of e: %s", last_e);
运行后在executon log中看到如下语句:
Starting action Action.
Action.c(12): We can see the first occurrence of e: ee is a tester
Action.c(14): We can see the last occurrence of e: er
3 Strcmp&stricmp
int strcmp ( const char *string1, const char *string2 );大小写敏感。
int stricmp ( const char *string1, const char *string2 );大小写不敏感。
功能:比较字符串。
例子:
按是否区分大小写对比两个字符串,并打印出它们的大小关系。
脚本如下:
int result;
char tmp[20];
char string1[] = "We can see the string:ZEE";
char string2[] = "We can see the string:zee";
result = strcmp( string1, string2 ); /*区分大小写,比较字符串 */
lr_output_message("The sentence has %d letters",len);
运行后在log中看到如下语句:
Action.c(13): The sentence has 15 letters
7 Strncat
char *strncat ( char *to_string, const char *from_string, size_t n );
把一个字符串连接到另一个字符串后面。
例子:
在这里,我随便写了两个字符串,用此函数把他们连接起来,并打印出来。
脚本如下:
char str1[]="Zee is ";
char str2[]="a tester.";
lr_output_message("What can we see?");
lr_output_message("The str1 is %s.",str1);
strncat(str1,str2,20);
lr_output_message("The str1 is %s.",str1);
运行后在log中看到如下语句:
Action.c(9): What can we see?
Action.c(10): The str1 is Zee is .
Action.c(13): The str1 is Zee is a tester..
注:我们可以看到,没有连接前的str1是:Zee is,连接后的字符串是:Zee is a tester。也可以看看strcat函数。
8 strncmp
int strncmp ( const char *string1, const char *string2, size_t n );
对比两个字符串的前n位。
例子:
对比两个字符串,并把对比结果打印出来。这里我和上面的strcmp一起写。
脚本如下:
char result;
char str1[]="Zee is a tester.";
char str2[]="Zee is a tester.";
char str3[]="zee is a tester?";
result = strcmp(str1,str2);
if(result > 0)
lr_output_message("str1 is greater than str2.");
else if(result < 0)
lr_output_message("str1 is less than str2.");
else
lr_output_message("str1 is equal to str2.");
result = strncmp( str1, str3 , 30);
if(result > 0)
lr_output_message("str1 is greater than str3.");
else if(result < 0)
lr_output_message("str1 is less than str3.");
else
lr_output_message("str1 is equal to str3.");
运行后在log中看到如下语句:
Starting iteration 1.
Starting action Action.
Action.c(18): str1 is equal to str2.
Action.c(28): str1 is less than str3.作者: kycq0102 时间: 2006-11-29 11:24
下面是录制代码中的一部分(LR自带的):
web_submit_form("login.pl",
"Snapshot=t2.inf",
ITEMDATA,
"Name=username", "Value=jojo", ENDITEM,
"Name=password", "Value=bean", ENDITEM,
"Name=login.x", "Value=0", ENDITEM,
"Name=login.y", "Value=0", ENDITEM,
LAST);