chopping strings

D

djm

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
 
S

Shadowman

djm said:
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

Use some combination of one or more of:

string::find
string::find_first_of
string::erase
 
D

djm

Use some combination of one or more of:

string::find
string::find_first_of
string::erase

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;
 
D

Default User

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,199
Messages
2,571,045
Members
47,643
Latest member
ashutoshjha_1101

Latest Threads

Top