How to remove accents and tilde in a C++ std::string

前端 未结 8 1371
半阙折子戏
半阙折子戏 2020-12-15 21:26

I have a problem with a string in C++ which has several words in Spanish. This means that I have a lot of words with accents and tildes. I want to replace them for their not

8条回答
  •  一整个雨季
    2020-12-15 22:07

    If you can (if you're running Unix), I suggest using the tr facility for this: it's custom-built for this purpose. Remember, no code == no buggy code. :-)

    Edit: Sorry, you're right, tr doesn't seem to work. How about sed? It's a pretty stupid script I've written, but it works for me.

    #!/bin/sed -f
    s/á/a/g;
    s/é/e/g;
    s/í/i/g;
    s/ó/o/g;
    s/ú/u/g;
    s/ñ/n/g;
    

提交回复
热议问题