区分大小写的字符串补偿用C [英] Case Insensitive String comp in C

查看:123
本文介绍了区分大小写的字符串补偿用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个交codeS 的char * ,我想比较,忽略大小写。
是否有一个函数来做到这一点?

I have two postcodes char* that I want to compare, ignoring case. Is there a function to do this?

还是我通过每个必须循环使用tolower的功能,然后做比较呢?

Or do I have to loop through each use the tolower function and then do the comparison?

不知道如何该功能将与数字字符串中的反应

Any idea how this function will react with numbers in the string

感谢

推荐答案

有没有的功能,这是否在C标准。与POSIX符合Unix系统都要求有<一个href=\"http://pubs.opengroup.org/onlinepubs/9699919799/functions/strcasecmp.html\"><$c$c>strcasecmp在头 strings.h ;微软系统有 stricmp 。为了在便携式侧,写你自己的:

There is no function that does this in the C standard. Unix systems that comply with POSIX are required to have strcasecmp in the header strings.h; Microsoft systems have stricmp. To be on the portable side, write your own:

int strcicmp(char const *a, char const *b)
{
    for (;; a++, b++) {
        int d = tolower(*a) - tolower(*b);
        if (d != 0 || !*a)
            return d;
    }
}

但要注意,这些解决方案将使用UTF-8字符串,只有那些ASCII工作。

But note that none of these solutions will work with UTF-8 strings, only ASCII ones.

这篇关于区分大小写的字符串补偿用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆