Convert ASCII string to Unicode? Windows, pure C

后端 未结 6 908
滥情空心
滥情空心 2021-01-13 06:08

I\'ve found answers to this question for many programming languages, except for C, using the Windows API. No C++ answers please. Consider the following:

#inc         


        
6条回答
  •  感情败类
    2021-01-13 06:46

    If you KNOW that the input is pure ASCII and there are no extended character sets involved, there's no need to call any fancy conversion function. All the character codes in ASCII are the same in Unicode, so all you need to do is copy from one array to the other.

    #include 
    char *string = "The quick brown fox jumps over the lazy dog";
    int len = strlen(string);
    WCHAR unistring[len+1];
    int i;
    for (i = 0; i <= len; ++i)
        unistring[i] = string[i];
    

提交回复
热议问题