943,691 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4127
  • C++ RSS
Oct 14th, 2005
0

deleting spaces in an ansistring

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ramcfloyn is offline Offline
10 posts
since Jul 2005
Oct 14th, 2005
0

Re: deleting spaces in an ansistring

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]
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ramcfloyn is offline Offline
10 posts
since Jul 2005
Oct 14th, 2005
0

Re: deleting spaces in an ansistring

Isn't std::string the ANSI string?

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

C++ Syntax (Toggle Plain Text)
  1. result.erase(result.find(' '));

To remove one space...

-Fredric
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
Daishi is offline Offline
80 posts
since Aug 2005
Oct 14th, 2005
0

Re: deleting spaces in an ansistring

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
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Timesaving Tips
Next Thread in C++ Forum Timeline: setting width and fill character...(a compiler issue?)





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC