Change all accented letters to normal letters in C++

后端 未结 7 1089
迷失自我
迷失自我 2021-02-13 10:18

The question

How can you change all accented letters to normal letters in C++ (or in C)?

By that, I mean something like eéèêaàäâçc would become

7条回答
  •  感动是毒
    2021-02-13 10:42

    char* removeAccented( char* str ) {
        char *p = str;
        while ( (*p)!=0 ) {
            const char*
            //   "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"
            tr = "AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiiOnooooo/0uuuuypy";
            unsigned char ch = (*p);
            if ( ch >=192 ) {
                (*p) = tr[ ch-192 ];
            }
            ++p; // http://stackoverflow.com/questions/14094621/
        }
        return str;
    }
    

提交回复
热议问题