Loadrunner中常用的C函数

发表于:2010-7-29 14:49

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

  将字符串中的数字转换为浮点数的函数,如果不事先声明,则转换有问题。

  1)strcat

  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);

  运行后在executon log中看到如下语句:

Starting action Action.
Action.c(16): We can see Cheers_Lee@hotmail.com

  2)strchr

  char *strchr ( const char *string, int c );

  功能:返回字符串中指定字符后面的字符串。

  例子:

  这个例子是返回第一个出现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);

  运行后在executon log中看到如下语句:

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

  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: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 );
result = stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "大于" );
else if( result < 0 )
strcpy( tmp, "小于" );
else
strcpy( tmp, "等于" );
lr_output_message( "stricmp: String 1 %s string 2", tmp );

  运行后在executon log中看到如下语句:

Starting action Action.
Action.c(22): strcmp: String 1  小于 string 2
Action.c(33): stricmp: String 1 等于 string 2

31/3123>
《2023软件测试行业现状调查报告》独家发布~

精彩评论

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号