标准的ANSI C字符串函数和它们的等价Unicode函数 字符串处理函数对照表[宽字符处理与ANSI字符处理]

来源:互联网 发布:游泳入池须知知乎 编辑:程序博客网 时间:2024/04/29 08:15

标准的ANSI C字符串函数和它们的等价Unicode函数


所有的Unicode函数均以wcs开头,wcs是宽字符串的英文缩写。若要调用Unicode函数,只需要用前缀wcs来取代ANSI字符串函数的前缀str即可。

常用函数对照

ANSIUNICODE通用说明数据类型(char.h)(wchar.h)(tchar.h) charwchar_tTCHAR char *wchar_t *TCHAR* LPSTRLPWSTRLPTSTR LPCSTRLPCWSTRLPCTSTR     字符串转换atoi_wtoi_ttoi把字符串转换成整数(int)atol_wtol_ttol把字符串转换成长整型数(long)atof_wtof_tstof把字符串转换成浮点数(double)itoa_itow_itot将任意类型的数字转换为字符串    字符串操作strlenwcslen_tcslen获得字符串的数目strcpywcscpy_tcscpy拷贝字符串strncpywcsncpy_tcsncpy类似于strcpy/wcscpy,同时指定拷贝的数目strcmpwcscmp_tcscmp比较两个字符串strncmpwcsncmp_tcsncmp类似于strcmp/wcscmp,同时指定比较字符字符串的数目strcatwcscat_tcscat把一个字符串接到另一个字符串的尾部strncatwcsncat_tcsnccat类似于strcat/wcscat,而且指定粘接字符串的粘接长度.strchrwcschr_tcschr查找子字符串的第一个位置strrchrwcsrchr_tcsrchr从尾部开始查找子字符串出现的第一个位置strpbrkwcspbrk_tcspbrk从一字符字符串中查找另一字符串中任何一个字符第一次出现的位置strstrwcsstr/wcswcs_tcsstr在一字符串中查找另一字符串第一次出现的位置strcspnwcscspn_tcscspn返回不包含第二个字符串的的初始数目strspnwcsspn_tcsspn返回包含第二个字符串的初始数目strtokwcstok_tcstok根据标示符把字符串分解成一系列字符串 wcswidth 获得宽字符串的宽度 wcwidth 获得宽字符的宽度    字符串测试isasciiiswascii_istascii测试字符是否为ASCII 码字符, 也就是判断c 的范围是否在0 到127 之间isalnumiswalnum_istalnum测试字符是否为数字或字母isalphaiswalpha_istalpha测试字符是否是字母iscntrliswcntrl_istcntrl测试字符是否是控制符isdigitiswdigit_istdigit测试字符是否为数字isgraphiswgraph_istgraph测试字符是否是可见字符isloweriswlower_istlower测试字符是否是小写字符isprintiswprint_istprint测试字符是否是可打印字符ispunctiswpunct_istpunct测试字符是否是标点符号isspaceiswspace_istspace测试字符是否是空白符号isupperiswupper_istupper测试字符是否是大写字符isxdigitiswxdigit_istxdigit测试字符是否是十六进制的数字大小写转换tolowertowlower_totlower把字符转换为小写touppertowupper_totupper把字符转换为大写字符比较strcollwcscoll_tcscoll比较字符串日期和时间转换strftimewcsftime_tcsftime根据指定的字符串格式和locale设置格式化日期和时间strptime  根据指定格式把字符串转换为时间值, 是strftime的反过程打印和扫描字符串printfwprintf_tprintf使用vararg参量的格式化输出到标准输出fprintffwprintf_ftprintf使用vararg参量的格式化输出scanfwscanf_tscanf从标准输入的格式化读入fscanffwscanf_ftscanf格式化读入sprintfswprintf_stprintf根据vararg参量表格式化成字符串sscanfswscanf_stscanf以字符串作格式化读入vfprintfvfwprintf_vftprintf使用stdarg参量表格式化输出到文件vprintf  使用stdarg参量表格式化输出到标准输出vsprintfvswprintf_vstprintf格式化stdarg参量表并写到字符串sprintf_sswprintf_s_stprintf_s格式化字符串数字转换strtodwcstod_tcstod把字符串的初始部分转换为双精度浮点数strtolwcstol_tcstol把字符串的初始部分转换为长整数strtoulwcstoul_tcstoul把字符串的初始部分转换为无符号长整数_strtoi64_wcstoi64_tcstoi64     输入和输出fgetcfgetwc_fgettc从流中读入一个字符并转换为宽字符fgetsfgetws_fgetts从流中读入一个字符串并转换为宽字符串fputcfputwc_fputtc把宽字符转换为多字节字符并且输出到标准输出fputsfputws_fputts把宽字符串转换为多字节字符并且输出到标准输出串getcgetwc_gettc从标准输入中读取字符, 并且转换为宽字符getchargetwchar_gettchar从标准输入中读取字符putcputwc_puttc标准输出putcharputwchar_puttchar标准输出ungetcungetwc_ungettc把一个字符放回到输入流中

 

用C函数来转换Unicode和ANSI文字

[cpp] view plain copy
 
 print?
  1. char sChar[MAX_PATH];  
  2. const WCHAR wChar[] = L"我的朋友";  
  3.   
  4. // 设置代码页为默认代码页  
  5. _tsetlocale(LC_ALL,_T(""));  
  6. // 把wChar这个Unicode字符串转换成ANSI字符串,保存到sChar,并且返回ANSI的字符串大小,如果失败,则返回-1  
  7. wcstombs(sChar, wChar, MAX_PATH);  
  8. // 相反的函数:mbstowcs,可以从ANSI转换到Unicode  
0 0