Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Mon, 30 Apr 2007 06:39:17 -0400, Ron Rosenfeld
wrote: On Mon, 30 Apr 2007 00:18:47 +0100, "Dave F." wrote: Hi I'm using HTTPRequest to download a page of stock prices from ADVFN. The part I want is of the format: prices[1]=25.25;prices[2]=2.15;prices[3]=100.5; etc... As you can see it's already passing it to an array within the page functions, but is downloaded as a string. Any ideas how can I parse this info into an array in VBA? I can split using the semi colon but not sure how to get the rest into the array. On a more general note, Does anyone know if there's a better way to obtain parts of a web page data without downloading it all & have to strip out the bits I want? Thanks in advance Dave F. Here's one idea. First replace the "prices...=" part of the string leaving a semicolon delimited string of prices. This uses Regular Expressions. If the line contains other data than what you have shown, the regex will need modification. But it shouldn't be too difficult. Then Split based on the semi-colon. ================================================= == Option Explicit Public Const sPrices As String = "prices[1]=25.25;prices[2]=2.15;prices[3]=100.5" Sub ParsePrices() Dim Prices As Variant Dim objRegExp As Object Dim objMatches As Object Dim i As Long Set objRegExp = CreateObject("VBScript.RegExp") objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.MultiLine = True objRegExp.Pattern = "prices\[\d+\]=" Prices = objRegExp.Replace(sPrices, "") Prices = Split(Prices, ";") 'Show parsed items For i = 0 To UBound(Prices) Debug.Print i, Prices(i) Next i End Sub ========================================== --ron There is an unnecessary Dim line in the above. ================================================== = Option Explicit Public Const sPrices As String = "prices[1]=25.25;prices[2]=2.15;prices[3]=100.5" Sub ParsePrices() Dim Prices As Variant Dim objRegExp As Object Dim i As Long Set objRegExp = CreateObject("VBScript.RegExp") objRegExp.IgnoreCase = True objRegExp.Global = True objRegExp.MultiLine = True objRegExp.Pattern = "prices\[\d+\]=" Prices = objRegExp.Replace(sPrices, "") Prices = Split(Prices, ";") 'Show parsed items For i = 0 To UBound(Prices) Debug.Print i, Prices(i) Next i End Sub ========================================== --ron |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
parsing a string | Excel Programming | |||
Parsing a string | Excel Programming | |||
Parsing a string | Excel Programming | |||
Need help parsing a string | Excel Programming | |||
parsing a string | Excel Programming |