Change all accented letters to normal letters in C++

后端 未结 7 1093
迷失自我
迷失自我 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 11:07

    Here is what you can do using ISO/IEC 8859-1 (ASCII-based standard character encoding):

    • if code range is from 192 - 197 replace with A
    • if code range is from 224 - 229 replace with a
    • if code range is from 200 - 203 replace with E
    • if code range is from 232 - 235 replace with e
    • if code range is from 204 - 207 replace with I
    • if code range is from 236 - 239 replace with i
    • if code range is from 210 - 214 replace with O
    • if code range is from 242 - 246 replace with o
    • if code range is from 217 - 220 replace with U
    • if code range is from 249 - 252 replace with u

    Supposing x is the code of the number, perform the following for capital letters:

    • y = floor((x - 192) / 6)
    • if y <= 2 then z = ((y + 1) * 4) + 61 else z = (y * 6) + 61

    Perform the following for small letters:

    • y = floor((x - 224) / 6)
    • if y <= 2 then z = ((y + 1) * 4) + 93 else z = (y * 6) + 93

    The final answer z is the ASCII code of the required alphabet.
    Note that this method works only if you are using ISO/IEC 8859-1.

    0 讨论(0)
提交回复
热议问题