Extracting name out of line

G

Gordon

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
 
R

Ron Rosenfeld

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

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
 
Top