| | |
deleting spaces in an ansistring
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 11
Reputation:
Solved Threads: 0
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?
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?
•
•
Join Date: Jul 2005
Posts: 11
Reputation:
Solved Threads: 0
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]
[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]
•
•
Join Date: Aug 2005
Posts: 80
Reputation:
Solved Threads: 2
Isn't std::string the ANSI string?
Why are you not using std::string? If you were you could just do...
To remove one space...
-Fredric
Why are you not using std::string? If you were you could just do...
C++ Syntax (Toggle Plain Text)
result.erase(result.find(' '));
To remove one space...
-Fredric
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
http://www.codepedia.com/1/CppBuilderGetExtension
![]() |
Similar Threads
- hijackthis log - please help (Viruses, Spyware and other Nasties)
- Deleting program (Windows NT / 2000 / XP)
- deleting registry key for error code 19 (Windows NT / 2000 / XP)
- Code not working for deleting recordfrom a file (Visual Basic 4 / 5 / 6)
- IE Cache not deleting a URL (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: Timesaving Tips
- Next Thread: setting width and fill character...(a compiler issue?)
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






