|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
hello everyone. ive a string with a blank space at the start
for eg: string str=" c++ rocks!"; how can i chop of that blank space of the string and display? thanks |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
djm wrote:
> hello everyone. ive a string with a blank space at the start > for eg: > string str=" c++ rocks!"; > how can i chop of that blank space of the string and display? Find the first character that isn't a space and erase all chars between the start of the string and that character. RTFM on how to find and how to erase. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"djm" <djmlog103@gmail.com> wrote in message
news:1192633612.268469.31450@q5g2000prf.googlegrou ps.com... > hello everyone. ive a string with a blank space at the start > for eg: > string str=" c++ rocks!"; > how can i chop of that blank space of the string and display? > thanks This is what I use. std::string trim( const std::string& text, const char TrimChar = ' ' ) { std::string::size_type First = text.find_first_not_of(TrimChar); if ( First == std::string::npos ) return ""; return text.substr( First, text.find_last_not_of(TrimChar) - First + 1); } Note it will trim any spaces (or specified character) from both the front and end of the string. |
|
![]() |
| Outils de la discussion | |
|
|