VC String Functions Summary ----VC字符串函数大全

来源:互联网 发布:54坐标系数据 编辑:程序博客网 时间:2024/06/06 07:15


VC中的字符串类型和处理函数是一个比较复杂的话题,今天的内容仅限于处理字符串的C函数。

这类函数共有四族,以取字符串长度的函数为例,四族函数如下:

strlen    str族
wcslen    wcs族
_mbslen   _mbs族
_tcslen   _tcs族

其中,前两个族的函数是C语言的标准库函数,以下划线开始的两族函数是VC中特有的函数,即微软的扩展函数。

这四族函数最大的区别是它们所用的字符集不同,或者说它们的参数类型不同。

str族是我们都比较熟悉的,它的参数类型是char*,这一族函数均以字节为单位进行处理,一个英文字符占一个字节,一个汉字占两个字节,因此strlen("中文ABC")的结果是7,字符串在内存中实际占用7个字节。

再说说wcslen,它的参数类型是wchar_t*,wchar_t称为宽字符,或者UNICODE字符,是用两个字节表示一个字符。UNICODE字符串都要在前面加上一个L前缀,因此,_wcslen(L"中文ABC")的结果是5,但字符串在内存中占10个字节。

_mbslen似乎很少用,它的参数类型是unsigned char*,_mbs族函数是为了处理汉字字符专门引入的,它以实际的字符为单位而不是以字节为单位进行处理,一个汉字是一个字符,因此_mbslen("中文ABC")的结果是5,但字符串在内存中占7个字节。

_tcslen称为自适应函数,它的参数类型是TCHAR,TCHAR是一个自适应类型。在UNICODE环境下_tcslen等效于wcslen,TCHAR等效于wchar_t,在非UNICODE环境下,_tcslen等效于strlen,TCHAR等效于char。因此,_tcslen(_T("中文ABC"))的结果可能是7或5,字符串本身在内存中可能占7个字节,也可能占10个字节,依环境而定。

综上所述,如果你的程序既要制作成UNICODE版,又要制作成非UNICODE版,最好使用_tcs族函数和TCHAR类型,并且每个字符串常量最好用_T()括起来。

bcmp(比较内存内容) 相关函数   bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp
表头文件   #include

bcopy(拷贝内存内容) 相关函数   memccpy,memcpy,memmove,strcpy,ctrncpy
表头文件   #include

bzero(将一段内存内容全清为零) 相关函数   memset,swab
表头文件   #include

index(查找字符串中第一个出现的指定字符) 相关函数   rindex,srechr,strrchr
表头文件   #include

memccpy(拷贝内存内容) 相关函数   bcopy,memcpy,memmove,strcpy,strncpy
表头文件   #include

memchr(在某一内存范围中查找一特定字符) 相关函数   index,rindex,strchr,strpbrk,strrchr,strsep,strspn,strstr
表头文件   #include

memcmp(比较内存内容) 相关函数   bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp
表头文件   #include

memcpy(拷贝内存内容) 相关函数   bcopy,memccpy,memcpy,memmove,strcpy,strncpy
表头文件   #include

memmove(拷贝内存内容) 相关函数   bcopy,memccpy,memcpy,strcpy,strncpy
表头文件   #include

memset(将一段内存空间填入某值) 相关函数   bzero,swab
表头文件   #include

rindex(查找字符串中最后一个出现的指定字符) 相关函数   index,memchr,strchr,strrchr
表头文件   #include

strcasecmp(忽略大小写比较字符串) 相关函数   bcmp,memcmp,strcmp,strcoll,strncmp
表头文件   #include

strcat(连接两字符串) 相关函数   bcopy,memccpy,memcpy,strcpy,strncpy
表头文件   #include

strchr(查找字符串中第一个出现的指定字符) 相关函数   index,memchr,rinex,strbrk,strsep,strspn,strstr,strtok
表头文件   #include

strcmp(比较字符串) 相关函数   bcmp,memcmp,strcasecmp,strncasecmp,strcoll
表头文件   #include

strcoll(采用目前区域的字符排列次序来比较字符串) 相关函数   strcmp,bcmp,memcmp,strcasecmp,strncasecmp
表头文件   #include

strcpy(拷贝字符串) 相关函数   bcopy,memcpy,memccpy,memmove
表头文件   #include

strcspn(返回字符串中连续不含指定字符串内容的字符数) 相关函数   strspn
表头文件   #inclued

strdup(复制字符串) 相关函数   calloc,malloc,realloc,free
表头文件   #include

strlen(返回字符串长度) 相关函数 表头文件   #include

strncasecmp(忽略大小写比较字符串) 相关函数   bcmp,memcmp,strcmp,strcoll,strncmp
表头文件   #include

strncat(连接两字符串) 相关函数   bcopy,memccpy,memecpy,strcpy,strncpy
表头文件   #inclue

strncpy(拷贝字符串) 相关函数   bcopy,memccpy,memcpy,memmove
表头文件   #include

strpbrk(查找字符串中第一个出现的指定字符) 相关函数   index,memchr,rindex,strpbrk,strsep,strspn,strstr,strtok
表头文件   #include

strrchr(查找字符串中最后出现的指定字符) 相关函数   index,memchr,rindex,strpbrk,strsep,strspn,strstr,strtok
表头文件   #include

strspn(返回字符串中连续不含指定字符串内容的字符数) 相关函数   strcspn,strchr,strpbrk,strsep,strstr
表头文件   #include

strstr(在一字符串中查找指定的字符串) 相关函数   index,memchr,rindex,strchr,strpbrk,strsep,strspn,strtok
表头文件   #include

strtok(分割字符串) 相关函数   index,memchr,rindex,strpbrk,strsep,strspn,strstr
表头文件   #include


0 0
原创粉丝点击