I am copying a line off the web with 4 names in it, separated by
spaces (From 1 to 6 spaces). I am trying to extract name 3 from the
line. Tried split(Var, " ") however Name moves according to the space
between the names. Var(2) can be the Name or according to spaces
between names, Var(6)
Can you help me?
Thank you, Gordon
Ron Rosenfeld - 28 Jan 2007 01:41 GMT
>I am copying a line off the web with 4 names in it, separated by
>spaces (From 1 to 6 spaces). I am trying to extract name 3 from the
[quoted text clipped - 5 lines]
>
>Thank you, Gordon
Here's an example using regular expressions. The example extracts all of the
names, but if you just want name 3, then:
Debug.print colMatches(2)
(the count is zero-based)
===================================
Option Explicit
Sub ParseNames()
Const T As String = "Name1 Name2 Name3 Name4"
Dim i As Long
Dim objRe As Object
Dim colMatches As Object
Const Pattern As String = "\w+"
Set objRe = CreateObject("vbscript.regexp")
objRe.Global = True
objRe.Pattern = Pattern
If objRe.test(T) = True Then
Set colMatches = objRe.Execute(T)
For i = 0 To colMatches.Count - 1
Debug.Print colMatches(i)
Next i
End If
End Sub
==============================
For just Name 3,
--ron