Click to See Complete Forum and Search --> : split string


jrthor2
03-31-2004, 03:06 PM
I have a function that returns the following string of data:

2:56 PM EST March 31, 20044946N/A80%43NE at 629.80Haze 305:51 AM (EST)06:30 PM (EST)HummelstownPennsylvania01:15 PM (EST)03:41 AM (EST)

What I would like is to split the data into different variables. For example, have a variable for last_updated = 2:56 PM EST March 31, 2004, temp = 49, wind_chill = 46, etc.

Is this possible?

drewex
03-31-2004, 04:30 PM
Is this text fixed or space delimited give some more examples. But you can use split, left, right, mid functions to get different parts in the text.

jrthor2
04-01-2004, 08:06 AM
No, it's not fixed or space delimeted. It's a string that comes back from a webservice, but it is not delimeted or anything. That's why I'm asking if it's possible.

buntine
04-01-2004, 08:27 AM
Your just going to have to use VBScripts string-handling functions.. I will do two of them so you know what i mean.

dim strLastUpdate, intWindChill, intTemp

strLastUpdate = CStr(Split(originalString, ",")(0) & ", " & Left(Split(originalString, ",")(1), 5))
intTemp = CInt(Mid(Split(originalString, ",")(1), 5, 2))
intWindChill = CInt(Mid(Split(originalString, ",")(1), 7, 2))

With Response
.Write (strLastUpdate & "<br />")
.Write (intTemp & "<br />")
.Write (intWindChill & "<br />")
End With


That may work for you.

Regards,
Andrew Buntine.

jrthor2
04-01-2004, 08:41 AM
I get this error:

Microsoft VBScript runtime error '800a000d'

Type mismatch: 'CInt'

/webservice_weather.asp, line 37



sub sendRequest(strZip, strKey)
dim SoapBody
if((strZip <> "") and (strKey <> "")) then
SoapBody = xmlSoap(strZip, strKey)
end if
response.write(SoapBody)
dim strLastUpdate, intWindChill, intTemp

strLastUpdate = CStr(Split(SoapBody, ",")(0) & ", " & Left(Split(SoapBody, ",")(1), 5))
intTemp = CInt(Mid(Split(SoapBody, ",")(1), 5, 2))
intWindChill = CInt(Mid(Split(SoapBody, ",")(1), 7, 2))

With Response
.Write ("<br>" & strLastUpdate & "<br>")
.Write (intTemp & "<br>")
.Write (intWindChill & "<br>")
End With

end sub

buntine
04-01-2004, 09:46 AM
So try something else.. You cant expect us to solve everything. I was only giving you an example of what you will need to do.

This stuff is only the fundalmentals of ASP.

Regards.