#include <ctype.h>
#include <string.h>
1、把多字符把轉換成寬字符
_CRTIMP size_t __cdecl mbstowcs(wchar_t *, const wchar* ,size_t);
2、將寬字符轉換成多字符
_CRTIMP size_t __cdecl wcstombs(char *mbstr, const wchar_t *wcstr, size_t count);
3、計算字符數
size_t __cdecl strlen(const char *);
_INTRIMP size_t __cdecl wcslen(const wchar_t *);
4、比較字符串
int __cdecl strcmp(const char *, const char *);
_INTRIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *);
5、拼接字符串
char * __cdecl strcat(char *, const char *);
_INTRIMP wchar_t * __cdecl wcscat(wchar_t *, const wchar_t *);
6、拷貝字符串
char * __cdecl strcpy(char *, const char *);
_INTRIMP wchar_t * __cdecl wcscpy(wchar_t *, const wchar_t *);
7、查找字符 返回地址
_CRTIMP char * __cdecl strchr(const char *, char);
_CRTIMP wchar_t * __cdecl wcschr(const wchar_t *, wchar_t);
8、查找字符 返回位置
_CRTIMP size_t __cdecl strcspn(const char *, const char *);
_CRTIMP size_t __cdecl wcscspn(const wchar_t *, const wchar_t *);
9、查找完全匹配的子字符串
_CRTIMP char * __cdecl strstr(const char *, const char *);
_CRTIMP wchar_t * __cdecl wcsstr(const wchar_t *, const wchar_t *);
10、按位置拼接字符串 const char* 前n的字符
_CRTIMP char * __cdecl strncat(char *, const char *, size_t);
_CRTIMP wchar_t * __cdecl wcsncat(wchar_t *, const wchar_t *, size_t);
11、分割字符串
_CRTIMP char * __cdecl strtok(char *, const char *);
_CRTIMP wchar_t * __cdecl wcstok(wchar_t *, const wchar_t *);
12、拷貝字符串 const char* 前n的字符
_CRTIMP char * __cdecl strncpy(char *, const char *, size_t);
_CRTIMP wchar_t * __cdecl wcsncpy(wchar_t *, const wchar_t *, size_t);
13、比較字符串 前n個字符
_CRTIMP int __cdecl strncmp(const char *, const char *, size_t);
_CRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t);
14、比較字符串,不區分字母的大小寫
_CRTIMP int __cdecl _stricmp(const char *, const char *);
_CRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *);
15、比較字符串的前n個字符串字典序的大小,不區分字母大小寫
_CRTIMP int __cdecl _strnicmp(const char *, const char *, size_t);
_CRTIMP int __cdecl _wcsnicmp(const wchar_t *, const wchar_t *, size_t);
16、檢驗參數1中的字符,當被檢驗字符在參數2中也包含時,返回該字符位置,空字符不包括在內。
_CRTIMP char * __cdecl strpbrk(const char *, const char *);
_CRTIMP wchar_t * __cdecl wcspbrk(const wchar_t *, const wchar_t *);
17、查找一個字符在另一個字符串中末次出現的位置
_CRTIMP char * __cdecl strrchr(const char *, char);
_CRTIMP wchar_t * __cdecl wcsrchr(const wchar_t *, wchar_t);
18、從參數1開頭計算連續字符,如字符完全是參數2中的字符。返回開頭連續包含的字符數目。
_CRTIMP size_t __cdecl strspn(const char *, const char *);
_CRTIMP size_t __cdecl wcsspn(const wchar_t *, const wchar_t *);
19、複製字符串 使用完後需要free()釋放內存,可直接複製CString中的字符串
_CRTIMP char * __cdecl _strdup(const char *);
_CRTIMP wchar_t * __cdecl _wcsdup(const wchar_t *);
20、將一個串中的前N個字符都設爲指定字符
_CRTIMP char * __cdecl _strnset(char *, char, size_t);
_CRTIMP wchar_t * __cdecl _wcsnset(wchar_t *, wchar_t, size_t);
21、把字符串的所有字符的順序顛倒過來(不包括空字符NULL)。
_CRTIMP char * __cdecl _strrev(char *);
_CRTIMP wchar_t * __cdecl _wcsrev(wchar_t *);
22、將一個串中的所有字符都設爲指定字符,不建議使用,該函數不會檢查‘\0’,容易導致內存錯誤
char * __cdecl _strset(char *, int);
_CRTIMP wchar_t * __cdecl _wcsset(wchar_t *, wchar_t);
23、將字符串轉換爲小寫形式
_CRTIMP char * __cdecl _strlwr(char *);
_CRTIMP wchar_t * __cdecl _wcslwr(wchar_t *);
24、將字符串轉換爲大寫形式
_CRTIMP char * __cdecl _strupr(char *);
_CRTIMP wchar_t * __cdecl _wcsupr(wchar_t *);
25、把字符轉換成小寫字母,非字母字符不做出處理
_CRTIMP char __cdecl tolower(char);
_CRTIMP wchar_t towlower(wchar_t);
26、把字符轉換成大寫字母,非字母字符不做出處理
_CRTIMP int __cdecl toupper(int);
_CRTIMP wchar_t towupper(wchar_t);
閱讀上述原文,請點擊這裏
《windows核心編程》P13-14 中寫道:
聲明Unicode字符和字符串的方法如下所示
wchar_t c=L'A';
wchar_t szBuffer[100]=L"A String";
在WinNT.h中定義了一系列能爲我們提供大量方便的數據類型,可以用它來處理字符指針和字符串指針
typedef char CHAR;
typedef wchar_t WCHAR;
typedef CHAR *PCHAR;
typedef CHAR *PSTR;
typedef CONST CHAR *PCSTR
typedef WCHAR *PWCHAR;
typedef WCHAR *PWSTR;
typedef CONST WCHAR *PCWSTR;
另外,WinNT.h還定義了下面的類型和宏,使用ANSI或Unicode字符/字符串都能通過編譯。
#ifdef UNICODE
typedef WCHAR TCHAR,*PTCHAR,PTSTR;
typedef CONST WCHAR *PCTSTR;
#define __TEXT(quote) quote//r_winnt
#define __TEXT(quote) L##quote
#else
typedef CHAR TCHAR, *PTCHAR,PTSTR;
typedef CONST CHAR *PCTSTR;
#define __TEXT(quote) quote
#endif
#define TEXT(quote) __TEXT(quote)
如下示例,都可以通過編譯,推薦此方法:
TCHAR C = TEXT('A');
TCHAR szBuffer[100] = TEXT("A String");
寬字節編寫的小demo
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
setlocale(LC_ALL, "");
TCHAR path[MAX_PATH];
GetSystemDirectory(path,MAX_PATH);
wcsncat(path,TEXT("\\cmd.exe"),9);
wcout<<path<<endl;
WCHAR s[] = L"你好";
wcout<<s<<endl;
getwchar();
return 0;
}
其中wout輸出中文的解決方法:
點擊這裏或打開下面鏈接
http://blog.csdn.net/ax614/article/details/6694625