我看过《女人不哭》 章子君的曲折生活,奋斗历程也让我更坚定的度过了那段日子。她最后还是成功了,事业and情感。从她身上,我学会: 坚强、忍耐、等待

LR_strcmp and LR_stricmp

上一篇 / 下一篇  2007-09-04 09:03:37 / 个人分类:LR_String Functions

一、strcmp

Comparesstring1andstring2to determine the alphabetic order.

intstrcmp (constchar *string1, const char *string2);//注意是int

string1
The first string that is compared.
string2
The second string that is compared.

strcmpcomparesstring1andstring2to determine the alphabetic order.

返回值:

Returns a value indicating the lexicographical relation between the strings:

Return value
Descrīption
<0
string1is less thanstring2
0
string1is the same asstring2
>0
string1is greater thanstring2
 
二、stricmp
(与strcmp的区别仅为忽略大小写)

Performs a case-insensitive comparison of two strings.

intstricmp(const char *string1, const char *string2);

string1
The first string for comparison.
string2
The second string for comparison.

stricmpperforms a case-insensitive comparison of two strings.

Returns a value indicating the lexicographical relation between the strings:

Return value
Descrīption
<0
string1is less thanstring2
0
string1is the same asstring2
>0
string1is greater thanstring2

脚本说明:

The following example compares two strings,string1andstring2, which are identical except for the word "quick" which is lowercase instring1and uppercase instring2.strcmp, which is case-sensitive, returns an unequal comparison.stricmp, which ignores case, returns an equal one.

下面的例子比较了两个字符串,string1和string2,除了单词"quick"在string1中为小写字母,在string2中为大写字母外,其他字母都是相同的。strcmp,是大小写敏感的,这个函数会返回一个不相同的结果。stricmp,会忽略大小写,返回相同的结果

 

#include "web_api.h"


Action() {

     int result;
     char tmp[20];
     char string1[] = "The quick brown dog jumps over the lazy fox";
     char string2[] = "The QUICK brown dog jumps over the lazy fox";

     result =strcmp( string1, string2 ); /* Case-sensitive comparison */

     if( result > 0 )
          strcpy( tmp, "greater than" );
     else if( result < 0 )
          strcpy( tmp, "less than" );
     else
          strcpy( tmp, "equal to" );

     lr_output_message( "strcmp: String 1 is %s string 2", tmp );

     result =stricmp( string1, string2 ); /* Case-insensitive comparison */

     if( result > 0 )
          strcpy( tmp, "greater than" );
     else if( result < 0 )
          strcpy( tmp, "less than" );
     else
          strcpy( tmp, "equal to" );

     lr_output_message( "stricmp: String 1 is %s string 2", tmp );

     return 0;
}

结果:

Action.c(20): strcmp: String 1 is greater than string 2
Action.c(31): stricmp: String 1 is equal to string 2


TAG:

 

评分:0

我来说两句

日历

« 2024-05-07  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 4269
  • 日志数: 6
  • 建立时间: 2007-07-21
  • 更新时间: 2007-09-04

RSS订阅

Open Toolbar