主题: c语言里不是经常用到的字符串操作函数

int strcoll ( const char * str1, const char * str2 );
根据LC_COLLATE设置的语言比较,如汉字按拼音比较。

size_t strcspn ( const char * str1, const char * str2 );
在str1里查找第一个包含在str2里的字符的位置。

size_t strspn ( const char * str1, const char * str2 );
返回str1中第一个不在str2中出现的字符下标

const char * strpbrk ( const char * str1, const char * str2 );
      char * strpbrk (       char * str1, const char * str2 );
在str1里查找第一个包含在str2里的字符,并返回其指针

char * strtok ( char * str, const char * delimiters );
用delimiters里的任一字符切分str(str只首次指定一次,且内容会被改变,需可写),返回当次切分的字符串指针。

size_t strxfrm ( char * destination, const char * source, size_t num );
根据当前locale转换source 指向的C字符串,并拷贝转换后的字符串的前num个字符到destination,返回值为长度.
此方法可以通过指定destination为null,num为0,来只求长度。
destination与source不能重叠
此方法的行为依赖于所选择的C locale的LC_COLLATE

2 最后由 cz (2014-06-17 17:42:58) 编辑

回复: c语言里不是经常用到的字符串操作函数

C locale作用范围

category
        Portion of the locale affected. It is one of the following constant values defined as macros in <clocale>:


value                Portion of the locale affected
------------------------------------------------------------
LC_ALL            The entire locale.
LC_COLLATE    Affects the behavior of strcoll and strxfrm.
LC_CTYPE            Affects character handling functions (all functions of <cctype>, except isdigit and isxdigit), and the multibyte
                        and wide character functions.
LC_MONETARY Affects monetary formatting information returned by localeconv.
LC_NUMERIC   Affects the decimal-point character in formatted input/output operations and string formatting functions, as
                       well as non-monetary information returned by localeconv.
LC_TIME          Affects the behavior of strftime.

回复: c语言里不是经常用到的字符串操作函数

可用的locale可以参见
/etc/locale.gen
把需要用到的编码去掉注释,然后执行下locale-gen,就可以使用了。