Get string from within string between chars.

SomeITGuy

New member
Local time
Today, 22:28
Joined
May 10, 2012
Messages
7
How do I extract a string from a larger string of varying values but after specific characters.

To be exact

<Things><other things of varying size>The text I need<stuff><more stuff of varying length>

Thanks
 
Can't use mid as there are varying char amounts on each side.
 
There are always the same amount of <text> sections on either side as it is a CSS page.
 
Could you give a small example? Of what is the String, what is the output you desire?
 
It grabs the following and I need to extract Nottingham and Bridge. The char length after bridge would always be the same so the last 93 characters can easily be whipped off. However the bits before it change in length depending on geographic location. I was thinking something along the lines of after 13 < > get the chars to the next < then after 11 more < > get the next lot of chars until <.

Thanks

<?xml version='1.0' encoding='UTF-8'?><ns2:SearchSByAByPostcodeResponseElemen><AreaFallsWithins><AreaFallsWithin><FallsWithin><Area><LevelTypeId>13</LevelTypeId><HierarchyId>2</HierarchyId><AreaId>276829</AreaId><Name>Nottingham</Name></Area></FallsWithin><Area><LevelTypeId>14</LevelTypeId><HierarchyId>24</HierarchyId><AreaId>6175515</AreaId><Name>Bridge</Name></Area></AreaFallsWithin></AreaFallsWithins></ns2:SearchSByAByPostcodeResponseElement>
 
Okay, I did this.. but not sure if this will be good enough for your implementation.. try it.. if it works great, else.. it should be somewhere aroud that line, so play around.. post back if still finding it hard.. the folloing will return NottinghamBridge..
Code:
Private Sub Command0_Click()
Dim str As String
Dim simple As String
Dim strArr() As String
str = "<?xml version='1.0' encoding='UTF-8'?><ns2:SearchSByAByPostcodeResponseElemen><AreaF allsWithins><AreaFallsWithin><FallsWithin><Area><L evelTypeId>13</LevelTypeId><HierarchyId>2</HierarchyId><AreaId>276829</AreaId><Name>Nottingham</Name></Area></FallsWithin><Area><LevelTypeId>14</LevelTypeId><HierarchyId>24</HierarchyId><AreaId>6175515</AreaId><Name>Bridge</Name></Area></AreaFallsWithin></AreaFallsWithins></ns2:SearchSByAByPostcodeResponseElement>"
strArr = Split(str, "<Name>")
For i = 0 To UBound(strArr)
    If Mid(strArr(i), 1, 1) <> "<" Then
        simple = simple & Left(strArr(i), InStr(strArr(i), "<") - 1)
    End If
Next
MsgBox (simple)
End Sub
 

Users who are viewing this thread

Back
Top Bottom