Как определить кодировку файла?

Рейтинг: 0Ответов: 0Опубликовано: 09.09.2014

Sorry for my bad english. I try to read the file with german umlauts in unknown code page. Here the lines, that i copied from notepad++ that encoding them in ANSI (?) code page:

4 CITY Mиunchen    
1 NAME иozkan/MиuLLER/

The client say that file in ANSEL (? but what) code page. I need to encode/decode them from/into CString. I use my own functions in MFC application:

    enum ECodePage {E_CP_ANSEL = 1250, E_CP_UTF8 = CP_UTF8, E_CP_ASCII = 20127,
 E_CP_UNKNOWN = FAIL, E_CP_NONE = NONE};

CString FilestringToCString(string str, ECodePage ecp) {
    if (str.empty())
        return STR_EMPTY;

    int nSizeNeed = MultiByteToWideChar(ecp, 0, &str[0],-1,NULL,0);
    wstring strFrom(nSizeNeed,0);
    MultiByteToWideChar(ecp, 0, &str[0],(int)str.size(),&strFrom[0],nSizeNeed);

    return strFrom.c_str();
}

string CStringToFilestring(CString str, ECodePage ecp) {
    if (str.IsEmpty())
        return STRING_EMPTY;

    int nSizeNeed = WideCharToMultiByte(ecp, 0, str,-1, NULL, 0, NULL, NULL);
    string strTo(nSizeNeed, 0);
    WideCharToMultiByte(ecp, 0, str,str.GetLength(),
        &strTo[0], nSizeNeed, NULL, NULL);

    return strTo;
}

CP_UTF8 - standard code page. Other code pages i take from
http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756(v=vs.85).aspx
I know that my code pages is 1250, 65001, 20127. And i named them ANSEL, UTF-8, ASCII respectively. It exactly and works well.
But client have its own files in ANSEL, ANSI, ASCII, WINDOWS and etc code pages.
Client ANSI - i read like my ANSEL - works well.
Client WINDOWS - read like ANSEL - works well.
Client ANSEL (file above) - i can't read (umlauts are down) in my code pages 1250 (ANSEL), 65001 (UTF-8), 20127 (ASCII).
I also tried read file like 1200, 12000, 65000 . I tried to find it code page online but it didn't work. Also i tried to read file in notepad++ code pages and total commander Lister code pages - didn't work. I can't read this umlauts.
How find exactly code page of this file?
Can anybody help please?

Ответы

Ответов пока нет.