deleting spaces in an ansistring

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 11
Reputation: ramcfloyn is an unknown quantity at this point 
Solved Threads: 0
ramcfloyn ramcfloyn is offline Offline
Newbie Poster

deleting spaces in an ansistring

 
0
  #1
Oct 14th, 2005
Hello, anyone familiar with ansiString?

Have a problem involving a string "1 1", should read "11".

I want to get rid of the space in the middle. Can't change it to a character string or std::string so that isn't an option. Will i have to compare each character inturn with " "?

Using ansiString.Pos(" ") to get position of the " ", but how should i go about removing the space and replacing it with the next character?
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 11
Reputation: ramcfloyn is an unknown quantity at this point 
Solved Threads: 0
ramcfloyn ramcfloyn is offline Offline
Newbie Poster

Re: deleting spaces in an ansistring

 
0
  #2
Oct 14th, 2005
OK here is what I've got at the minute:

[PHP]
String fixString(inputString)
{
result = inputString;
int string_size = result.Length();
while(result.Pos(" "))
{
int space = result.Pos(" ");
for (int i = space; i < string_size; i++)
{
result[space] = result[space+1];
string_size--;
}
}
result.SetLength(string_size);
return result;
}
[/PHP]
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 80
Reputation: Daishi is an unknown quantity at this point 
Solved Threads: 2
Daishi Daishi is offline Offline
Junior Poster in Training

Re: deleting spaces in an ansistring

 
0
  #3
Oct 14th, 2005
Isn't std::string the ANSI string?

Why are you not using std::string? If you were you could just do...

  1. result.erase(result.find(' '));

To remove one space...

-Fredric
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,639
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1497
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: deleting spaces in an ansistring

 
0
  #4
Oct 14th, 2005
ansiString is Borland's C++ builder string class. you can use its SubString method to remove the space. I don't use that compiler, but googled a bit and found this in about 5 seconds.

http://www.codepedia.com/1/CppBuilderGetExtension
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 3288 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC