字符串比较函数

来源:互联网 发布:数据库王珊第五版答案 编辑:程序博客网 时间:2024/05/29 07:52

在C/C++中的字符串比较函数,基本上可以分为两类:

1、大小写敏感的字符串比较函数;

2、忽略大小写的字符串比较函数;


1、大小写敏感的字符串比较函数:

       int strcmp( const char *s1, const char *s2 );

       int strncmp( const char *s1, const char *s2 );

      返回值: s1 > s2       return  > 0;

                     s1 == s2     return  0;

                     s1 < s2       return < 0;

      英文解释: strcmp() and strncmp() return an integer less than, equal to, or greater than zero if s1 is found to be less than, or match, or be greater than s2;

2、忽略大小写的字符串比较函数( compare two string ignoring case):

         int strcasecmp( const char *s1, const char *s2 );

         int strncasecmp( const char *s1, const char *s2 );

       返回值: s1 > s2    return > 0;

                      s1 == s2  return 0;

                      s1 < s2    return < 0;

       英文解释:strcasecmp() and strncasecmp() return an integer less than , equal to , or greater than zero if s1 is found to be less than, to match, or to be greater than s2;


1 0
原创粉丝点击