473,378 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

chopping strings

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

Oct 17 '07 #1
3 4081
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
Use some combination of one or more of:

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

--
SM
rot13 for email
Oct 17 '07 #2
djm
On Oct 17, 8:27 pm, Shadowman <funqbjzna...@pbzpnfg.argwrote:
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

Use some combination of one or more of:

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

--
SM
rot13 for email
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;

Oct 17 '07 #3
djm wrote:
On Oct 17, 8:27 pm, Shadowman <funqbjzna...@pbzpnfg.argwrote:
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
Oct 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Ravi | last post by:
Hi, I have about 200GB of data that I need to go through and extract the common first part of a line. Something like this. >>>a = "abcdefghijklmnopqrstuvwxyz" >>>b = "abcdefghijklmnopBHLHT"...
17
by: Gordon Airport | last post by:
Has anyone suggested introducing a mutable string type (yes, of course) and distinguishing them from standard strings by the quote type - single or double? As far as I know ' and " are currently...
16
by: Paul Prescod | last post by:
I skimmed the tutorial and something alarmed me. "Strings are a powerful data type in Prothon. Unlike many languages, they can be of unlimited size (constrained only by memory size) and can hold...
3
by: Cavello | last post by:
Hi, I'm curious as to how I can input a string of characters and then output it in sections, seperating these sections according to a particular value entered, for example a period. Say if I enter...
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
25
by: Rainmaker | last post by:
Hi, Can anyone tell me an efficient algorithm to sort an array of strings? Keep in mind that this array is HUGE and so the algorithm should me efficient enough to deal with it. Thanks
6
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an...
2
by: Potiuper | last post by:
Question: Is it possible to use a char pointer array ( char *<name> ) to read an array of strings from a file in C? Given: code is written in ANSI C; I know the exact nature of the strings to be...
95
by: hstagni | last post by:
Where can I find a library to created text-based windows applications? Im looking for a library that can make windows and buttons inside console.. Many old apps were make like this, i guess ...
7
by: Paul Furman | last post by:
mysql_real_escape_string() is apparently chopping off anything that follows a quote when I grab the data & put it in a form for editing. Sorry if I'm not explaining this properly, I'm pretty...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.