Remove characters from string

Jun 30, 2012 at 3:56pm
I want to remove the initial and final " character from my string:

string str("\"aaaa\""); // "aaaa"

How can I do using standard c++ or boost library?
Thanks.
Last edited on Jun 30, 2012 at 3:57pm
Jun 30, 2012 at 4:31pm
str=str.substr(1,str.length()-2);
Jun 30, 2012 at 4:56pm
No! But thanks for trying.

I resolved with:

boost::trim_if(str, is_any_of("\""));

or

boost::erase_all(str, "\"");
Last edited on Jun 30, 2012 at 4:56pm
Jun 30, 2012 at 5:05pm
@GliderKite

You are wrong. Your task as you described it is to delete initial and final " characters.

This code

boost::erase_all(str, "\"");

does another task that is it deletes all occurence of \".

And it is a very bad practice to use boost when the task can be simply done with standard means.

So the code suggested by Athar is much better.
Last edited on Jun 30, 2012 at 5:06pm
Topic archived. No new replies allowed.