Chinaunix首页 | 论坛 | 博客
  • 博客访问: 17911085
  • 博文数量: 7460
  • 博客积分: 10434
  • 博客等级: 上将
  • 技术积分: 78178
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-02 22:54
文章分类

全部博文(7460)

文章存档

2011年(1)

2009年(669)

2008年(6790)

分类: C/C++

2008-05-26 22:14:47

注意:
1,将字符串中的数字转换为浮点数的函数,如果不事先声明,则转换有问题。
1       strcat
 
char *strcat ( char *to, const char *from );
 
功能:链接两个字符串。
 
例子:
 
这个例子是用strcat链接字符串:zee和slo@hotmail.co
 
脚本如下:

 
     char test[1024], *a = "slo@hotmail.com";
 
     strcpy(test, "zee");
 
     strcat(test, a);
 
     lr_output_message("We can see %s",test);
 

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

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

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 ( constchar *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 ); /*区分大小写,比较字符串 */
 
     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

  
4       strcpy
char *strcpy ( char *dest, const char *source );
 
功能:复制一个字符串到另一个字符串中。
 
例子:
 
复制一个字符串到字符数组中,并打印出来。
 
脚本如下:
 

     char test[1024];
 
     strcpy(test, "what can we see?       ");
 
     lr_output_message("%s", test);

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

Starting action Action.
Action.c(10): what can we see?      

5       strdup
char *strdup ( const char *string );
 
复制一个字符串。
 
例子:
 
在这个例子中,Vuser的组名被转换为小写字母。但是lr_whoami把组名作为静态buffer返回。这样的buffer不能被操作。如果有操作需要,就和复制这个静态buffer。
 
脚本如下:
 

     int id;
    char *groupname_static, *groupname;
 
     /* 从VuGen中得到组名 */
     lr_whoami(&id, &groupname_static, NULL);
     lr_output_message("groupname=%s", groupname_static);
 
     /*复制这个静态组名以便我们可以操作它 */
     groupname = (char *)strdup(groupname_static);
     groupname = (char *)strlwr(groupname);
     lr_output_message("lower case groupname=%s", groupname);
 
     free(groupname);

上述脚本用vugen保存为:CHANGE
 
在controller中运行(设置为总是发送消息)
运行后在log中看到如下语句:

Starting action Action.    [MsgId: MMSG-15919]
Action.c(11): groupname=CHANGE     [MsgId: MMSG-17999]
Action.c(16): lower case groupname=change      [MsgId: MMSG-17999]

 
阅读(477) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~