C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

remove characters from a string

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
seawind
Guest





PostPosted: Tue Aug 29, 2006 4:40 pm    Post subject: remove characters from a string Reply with quote



I am a newer, and now i encounter a simple question.

i want to erase all specified characters ,such as ',' , from a string.
which function should i call?
for example:

string ls( "i ,am, a ,dog,");

thanks in advace

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Jens Theisen
Guest





PostPosted: Tue Aug 29, 2006 8:16 pm    Post subject: Re: remove characters from a string Reply with quote



===================================== MODERATOR'S COMMENT:

I have allowed this message through as a reply to a previous post, but material of this form is generally off-topic; please do not continue this thread unless topical material (i.e., material related to standardization of C++) is involved.


===================================== END OF MODERATOR'S COMMENT
seawind wrote:
Quote:
I am a newer, and now i encounter a simple question.

i want to erase all specified characters ,such as ',' , from a string.
which function should i call?
for example:

string ls( "i ,am, a ,dog,");

ls.erase(std::remove(ls.begin(), ls.end(), ','), ls.end())

This also works with other containers. It may seem weird, but it's the
ususal way of doing it in the STL.

You should get yourself a good book about the STL, because a reference
alone isn't enough; you need to know some idioms and concepts.

Jens

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
seawind
Guest





PostPosted: Wed Aug 30, 2006 4:15 am    Post subject: Re: remove characters from a string Reply with quote



===================================== MODERATOR'S COMMENT:

I'm approving this because it's a response to something that was already
posted, but let's be careful to keep this discussion on-topic. This
discussion is going in a direction that's not directly related to
standardization.

------=_Part_12514_9434602.1156907695370
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

approve<br>comment<br>I'm approving this because it's a response to something that was already posted, but let's be careful to keep this discussion on-topic. This discussion is going in a direction that's not directly related to standardization.
<br>

------=_Part_12514_9434602.1156907695370--


===================================== END OF MODERATOR'S COMMENT

According to what you said, i try it and it is ok,
thank you for your help and your advice.

and i try another algorithm remove as well. look like this,

string ls(" i , am , dog");

remove(ls.begin(), ls.end(), ',');

of course, i have used namespace std. and i get "i am dogog".
i traced into the function,and found that in fact it calls remove_copy.

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Jens Theisen
Guest





PostPosted: Wed Aug 30, 2006 9:25 pm    Post subject: Re: remove characters from a string Reply with quote

seawind wrote:
Quote:
of course, i have used namespace std. and i get "i am dogog".
i traced into the function,and found that in fact it calls remove_copy.

I'll post an answer to comp.lang.c++, as this is off topic here and the
moderators are getting angry I think. :)

Jens

---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.