How to remove double quotes from a string in C++

2 Answers

0 votes
#include <iostream>

int main() {
    std::string s = "\"c++ \"node.js\" c c++ c# python\"";
    std::cout << s << '\n';
    
    size_t pos = 0;
    while ((pos = s.find('"', pos)) != std::string::npos)
        s = s.erase(pos, 1);

    std::cout << s;
}




/*
run:

"c++ "node.js" c c++ c# python"
c++ node.js c c++ c# python

*/

 



answered Feb 20, 2022 by avibootz
0 votes
#include <iostream>
#include <algorithm>

int main() {
    std::string s = "\"c++ \"node.js\" c c++ c# python\"";
    std::cout << s << '\n';
    
    s.erase(remove(s.begin(), s.end(), '\"'), s.end()); 

    std::cout << s;
}




/*
run:

"c++ "node.js" c c++ c# python"
c++ node.js c c++ c# python

*/

 



answered Feb 20, 2022 by avibootz

Related questions

1 answer 125 views
1 answer 132 views
1 answer 138 views
1 answer 128 views
1 answer 124 views
2 answers 168 views
...