utf8转多字节

来源:互联网 发布:执业药师网络培训 编辑:程序博客网 时间:2024/05/21 10:24
char* Utf82Unicode(const char* utf, size_t *unicode_number)  {      if(!utf || !strlen(utf))      {          *unicode_number = 0;          return NULL;      }      int dwUnicodeLen = MultiByteToWideChar(CP_UTF8,0,utf,-1,NULL,0);      size_t num = dwUnicodeLen*sizeof(wchar_t);      wchar_t *pwText = (wchar_t*)malloc(num);      memset(pwText,0,num);      MultiByteToWideChar(CP_UTF8,0,utf,-1,pwText,dwUnicodeLen);      *unicode_number = dwUnicodeLen - 1;      return (char*)pwText;  }   char* Unicode2Ansi(const char* unicode)  {      int len;      len = WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)unicode, -1, NULL, 0, NULL, NULL);      char *szUtf8 = (char*)malloc(len + 1);      memset(szUtf8, 0, len + 1);      WideCharToMultiByte(CP_ACP, 0, (const wchar_t*)unicode, -1, szUtf8, len, NULL,NULL);      return szUtf8;  } char* ConvertUtf2Ansi(const char* str)  {    size_t i=0;    char* unicode = Utf82Unicode(str,&i);    char* utf8 = Unicode2Ansi(unicode);      free(unicode);      return utf8;  }
0 0
原创粉丝点击