How to strip all non alphanumeric characters from a string in c++?

后端 未结 11 1470
野的像风
野的像风 2020-11-30 02:07

I am writing a piece of software, and It require me to handle data I get from a webpage with libcurl. When I get the data, for some reason it has extra line breaks in it. I

11条回答
  •  孤独总比滥情好
    2020-11-30 02:28

    Below code should work just fine for given string s. It's utilizing and libraries.

    std::string s("He!!llo  Wo,@rld! 12 453");
    s.erase(std::remove_if(s.begin(), s.end(), [](char c) { return !std::isalnum(c); }), s.end());
    

提交回复
热议问题