View Full Version : Parsing A String and Converting to Int

02-16-2003, 04:38 AM
I searched the forum and found this:

Since all variables in ASP are actually of the type "Variant", you shouldn't have to "convert" it to numeric before performing a mathematical operation on it if it is indeed numeric (and I presume you set the cookie!). What are you trying to do, and what kind of information does the cookie contain?

CInt(variable) = integer
CDbl(variable) = Double

and there's plenty more datatypes, look on MSDN

But I am having trouble converting a passed timer string where:

Elapsedtime= 'request.form("ElapsedTime")

Elapsedtime is in the string format: '2:32' or 2 Min 32 Secs.

I want to parse and get the mod of 232/60 so I can convert to a message of " Your Time Was: 2 Min and 32 Secs"

Any suggestions, tips or direction will be appreciated.



02-16-2003, 05:59 AM
Why not just get rid of the ":"??

Mod is easy once you do that...

02-16-2003, 06:32 AM
Wait a sec, why are you going to Mod 232 by 60? That will give you the remainder after dividing, if you just split up the variable you can print it as "your time was 2 mins and 32 seconds." easily.

I might not be getting what you are trying to do but from what my feeble mind is telling me using Mod will achieve nothing. (well nothing that you can use)

I would just split() it. :confused:

02-16-2003, 04:35 PM
You are correct about the Mod.

What i need is the 2:32 converted to seconds 152.

LOL, sorry, but I need to know how to split that little : out as well.

Thx for your time.

02-16-2003, 05:22 PM
Elapsedtime= request.form("ElapsedTime")

If InStr(1,Elapsedtime,":") Then
Elapsedtimearray = Split(Elapsedtime,":")
End If

If IsArray(Elapsedtimearray) Then
Response.Write(Elapsedtimearray(0) & " minutes and " Elapsedtimearray(1) & " seconds.<br />" & vbCrLf)
End If

02-16-2003, 07:10 PM
Thank you Whammy. That split function is what I was looking for, as I did not know the proper syntax and usage.

After minor typo in 1st If (it needed an & ) I just added:

TotalTime =Cint(theElapsedtimearray(0))* 60 + Cint(theElapsedtimearray(1))

To the 2nd If Statement.

That gives me total seconds to derive a score I am doing!

Thx To all, again!:thumbsup:

02-17-2003, 02:32 AM