Discussion: chopping strings
Afficher un message
Vieux 17/10/2007, 18h43   #4
Default User
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: chopping strings

djm wrote:

> On Oct 17, 8:27 pm, Shadowman <funqbjzna...@pbzpnfg.arg> wrote:
> > 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?
> > > thanks


You can call it that if you want, but usually "chop" means to remove
the last character of a string. I've seen "ltrim" for removing leading
characters, there are probably other names.

> thanks shadow man. i used string::erase to do it
> did it like this
>
> string str (" c++ rocks!");
> str.erase (0,1);
> cout << str << endl;


This will always remove the first character (and only that one),
regardless of whether it's whitespace or not. Is that what you want?




Brian
  Réponse avec citation
 
Page generated in 0,05063 seconds with 9 queries