char *strcat ( char *to, const char *from );
功能:链接两个字符串。
例子:
这个例子是用strcat链接字符串:Cheers_Lee和 @hotmail.com
脚本如下:
char test[1024], *a = "@hotmail.com";
strcpy(test, "Cheers_Lee");
strcat(test, a);
lr_output_message("We can see %s",test);
运行后在executonlog中看到如下语句:
Starting action Action.
Action.c(16): We can seeCheers_Lee@hotmail.com
char *strchr ( const char *string, int c );
功能:返回字符串中指定字符后面的字符串。strchr函数
例子:
这个例子是返回第一个出现e字符以后所有的字符,和最后一次出现e字符以后所有的字符。
脚本如下:
char *string = "Cheers 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);
运行后在executonlog中看到如下语句:
Starting action Action.
Action.c(12): We can see the first occurrence of e: eers is a tester
Action.c(14): We can see the last occurrence of e: er
int strcmp ( const char *string1, const char *string2 );大小写敏感。
int stricmp ( const char *string1, const char *string2 );大小写不敏感。
功能:比较字符串。strchr函数
例子:
按是否区分大小写对比两个字符串,并打印出它们的大小关系。
脚本如下:
int result;
char tmp[20];
char string1[] = "We can see the string:Cheers";
char string2[] = "We can see the string:cheers";
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "大于" );
else if( result < 0 )
strcpy( tmp, "小于" );
else
strcpy( tmp, "等于" );
lr_output_message( "strcmp: String 1 %s string 2", tmp );
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-38054-1.html
这也不能吃