Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removal of Spaces from Input strings

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Help

Can anyone tell me how I can strip the initial spaces from an input string and store the remaining string. For example if &quot;<space><space>Hello<space>World&quot; is entered. I need to strip the first 2 spaces from the text to leave me with&quot;Hello<space>World&quot;.
The code needs to be written as a void method ie
void TrimFront(AnsiString &Str)
and called by the main command &quot;TrimFront(Line)&quot; where Line is the original input String.

Thanks in advance
 
Look at thread206-80258 and thread206-36289 for some hints. If you get stuck or need further help, post back here.

James P. Cottingham
 
Why don't u just use the AnsiString Trim function or TrimLeft or TrimRight
 
if u reading from a file and you have the ifstream in(&quot;file.txt&quot;)
then in.get();and againin.get() would remove the two spaces and place the cursors before h of hello world. then you acn use in.getline to take in the rest og the string with the spaces without providing any delimiter. if instead of fstream u use the input directly from the screen u can use cin.get() and cin.getline() in respective places where u used the 'in' of the fstream before before..
take care and have a nice time
 
do the trim, Like this:

AnsiString Hello = &quot;Hello World&quot;;

Trim (Hello);

thats all there is to it Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top