Solved

Get an array of strings from text

Posted on 2013-10-31
2
230 Views
Last Modified: 2013-10-31
I need to retrieve all values between @p_ and space from a string into an array in VBA.

For example, from this string:
"<willbe name=""Current24' value='if(g_movsum(loan_nid;;;current_flag;24;@p_lag )=24;1;0)'/> <willbe name=@p_name value=@p_value *(Current12)'/>"
I need an array with: @p_lag, @p_name, @p_value
0
Comment
Question by:leonstryker
2 Comments
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 39614392
Perhaps:

Function GetPdata(strIn As String)
   Dim matches
   Dim asOut() As String
   Dim n As Long
   
   With CreateObject("vbscript.regexp")
      .Pattern = "(@p_[^ ]+)"
      .Global = True
      If .test(strIn) Then
      Set matches = .Execute(strIn)
      ReDim asOut(matches.Count - 1)
      For n = 0 To matches.Count - 1
         asOut(n) = matches(n)
      Next n
         GetPdata = asOut
      Else
         GetPdata = ""
      End If
   End With

End Function

Open in new window

0
 
LVL 29

Author Closing Comment

by:leonstryker
ID: 39614410
Perfect, thank you for your help.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question