Hii..
I m using string vector my element set is L1 L2 L3 L4 L5 what i want now is to remove the whitespaces. so that my elements become L1L2L3L4L5.
I tried using remove but it doesn't check as it can't find a whitespace separately means when it iterate over second element it's "spaceL2" and not space so it simply ignore that same problem with find method method as well.
Kindly help
tonyaim83
-2
Light Poster
Recommended Answers
Jump to Postpost code and an actual example string. For example: "a b c" replaced by "abc". If that's what you want to do when code a while loop something like this:
string::size_t pos; while( (pos = mystring.find(' ')) != string::npos) { mystring = mystring.substr(0,pos) + mystring.substr(pos+1); }
Jump to PostSlightliy more complicated. You need to use a reference to the string in the vector. The algorithm below removes white space found anywhere in the string.
for(vector<string>::iterator it=vertex.begin();it!=vertex.end();it++) { std::string& mystring = *it; std::size_t pos; while( (pos = mystring.find_first_of(" \t\r\n")) != string::npos) { if(pos > 1) { …
Jump to PostNow i have to again add this to the original vector how should i do that
Please re-read my previous post becasue I tested and changed it. That algorithm works.
All 12 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tonyaim83
-2
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tonyaim83
-2
Light Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
vijayan121
1,152
Posting Virtuoso
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tonyaim83
-2
Light Poster
vijayan121
1,152
Posting Virtuoso
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tonyaim83
-2
Light Poster
Bench
212
Posting Pro
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.