Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Parsing a string into an array?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing a string BorisS Excel Programming 0 April 23rd 07 02:14 AM
Parsing a string neverends Excel Programming 2 June 7th 06 05:38 PM
Parsing a string simonc Excel Programming 4 March 27th 06 08:04 AM
Need help parsing a string Daminc[_38_] Excel Programming 4 January 26th 06 11:53 AM
parsing a string Mark[_57_] Excel Programming 4 April 28th 05 04:42 PM


All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"