"ucfcpegirl 06" <tr************ **@gmail.com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
Hi, I need help getting rid of trailing white spaces. I am searching a
file for various data (not important) and retrieving it. I output the
data if found to a file. An example would be:
HD='Three blind mice '
My output would consist of:
Three Blind Mice (w/ all the white space behind being printed until the
quote mark is reached)
I don't the white space after the text to be printed.
How do I get rid of trailing white spaces?
You've not stated how you are storing the string. The example provided is
not a string (ie: 'c' vs "a string"). Here is an example of stripping spaces
using a std::string:
#include <iostream>
#include <string>
std::string stripspaces(con st std::string& r_s)
{
int nstart = r_s.find_first_ not_of(' ');
int nend = r_s.find_last_n ot_of(' ') - 1;
std::string s_result = r_s.substr(nsta rt, nend);
return s_result;
}
int main()
{
std::string s(" a simple string ");
std::cout << "original string\n\t\tsta rt->" << s;
std::cout << "<-end" << std::endl;
std::cout << "stripped string\n\t\tsta rt->" << stripspaces(s);
std::cout << "<-end" << std::endl;
return 0;
}
/* output:
original string
start-> a simple string <-end
stripped string
start->a simple string<-end
*/