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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a string

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
0
0
US
I have a string that is like this:

2:00:00 PM

I want to take out the colons and out it in this format 20000PM

How can I do this?

Mindy
 
Greetings!

Try to use this code:

do
{
k = Pos(":");
if(!k)
break;
string.Delete(k,1);
while(false);


or another

for(i = 0; i < 2; i++)
string.Delete(Pos(&quot;:&quot;),1);


The first code is independent from a quantity of colon symbols and it may be used for deleting an unknown quantity of this symbols, the last code is used for deleting the only two colon chars if there exists, if it absent, the code fails
 
My colleague Pavlo always in a hurry.
Next code is really what you need.
I supposed, that str is AnsiString, and it contains
something like this:

2:00:00 PM


//-------------------------------
for(int x = 1;x <= str.Length();x++)
if(str[x] == ':' ||
str[x] == ' ')
str.Delete(x,1);
//---------------------------------

 
Greetings!

But i little fix DrLector's code!

for(int x = 1;x <= str.Length();x++)
if(str[x] == ':' ||
str[x] == ' ')
str.Delete(x--,1);


His code is right but non-universal, and it cant delete colon stand after each other.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top