是什么的strcmp(),并与strcoll()之间的区别? [英] What is the difference between strcmp() and strcoll()?

查看:209
本文介绍了是什么的strcmp(),并与strcoll()之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着理解他们两个,但我没有找到,除了的strcoll()这个参考说它

I tried understanding both of them but I did not find any differences except for strcoll() this reference says that it

比较两个空根据由LC_COLLATE类别定义当前的区域结尾的字符串。

compares two null terminated strings according to current locale as defined by the LC_COLLATE category.

在第二个想法,我知道我问了详细的回答另一个问题,究竟是这个区域,为C和C ++?

On the second thoughts and I know I am asking another question for detailed answer, what exactly is this locale, for both C and C++?

推荐答案

的strcmp()由一个取字符串之一的字节,因为是任何字节进行比较是。

strcmp() takes the bytes of the string one by one and compare them as is whatever the bytes are.

的strcoll()取个字节,使用的语言环境改造他们,然后将结果进行比较。改造重新订单根据语言。在法语中,突出的字母来非突出的人后。因此,é为后的电子邮件即可。然而,é是之前的˚F的strcoll()得到它的权利。 的strcmp()不是那么好。

strcoll() takes the bytes, transform them using the locale, then compares the result. The transformation re-orders depending on the language. In French, accentuated letters come after the non-accentuated ones. So é is after e. However, é is before f. strcoll() gets it right. strcmp() not so well.

不过,在很多情况下,的strcmp()就够了,因为你并不需要显示在使用的语言(区域)命令的结果。例如,如果你只需要快速访问大量由你使用的地图由字符串索引的索引字符串数据。这可能是完全无用使用这些排序的strcoll()通常是很慢(相比于的strcmp()至少。)

However, in many cases strcmp() is enough because you don't need to show the result ordered in the language (locale) in use. For example, if you just need to quickly access a large number of data indexed by a string you'd use a map indexed by that string. It probably is totally useless to sort those using strcoll() which is generally very slow (in comparison to strcmp() at least.)

有关字符的详细信息,你可能还需要检查出的统一code 网站。

For details about characters you may also want to check out the Unicode website.

在考虑到区域,它的语言。默认情况下它设置为C(多还是少,没有区域)。一旦你选择一个位置区域设置相应的设置。您还可以设置LC_LOCALE环境变量。其实有很多这样的变量。但在一般使用predefined功能,可以自动把这些变量的帐户,并为你做正确的事情。 (即格式的日期/时间,数字格式/措施,计算大/小写等)

In regard to the locale, it's the language. By default it is set to "C" (more or less, no locale). Once you select a location the locale is set accordingly. You can also set the LC_LOCALE environment variable. There are actually many such variables. But in general you use predefined functions that automatically take those variables in account and do the right thing for you. (i.e. format dates / time, format numbers / measures, compute upper / lower case, etc.)

这篇关于是什么的strcmp(),并与strcoll()之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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