Spliting a String

harrisw

Registered User.
Local time
Today, 13:43
Joined
Mar 27, 2001
Messages
131
Is there a way to find the first space from the right hand side of a string ie finding the surname out of a name string?
 
This works like the Instr() function, in reverse.

Function xLastInStr(tstr As String, twhat As String) As Integer
'*******************************************
'Name: xLastInStr (Function)
'Purpose: Return location of last instance of a character or phrase.
'Inputs: Call xLastInStr("the quick brown fox jumped the lazy dog", "the")
'Output: 28 - Location of last occurence of "the"
'*******************************************

Dim i As Integer, n As Integer, tlen As Integer

n = 0
tlen = Len(twhat)
For i = Len(RTrim(tstr)) To 1 Step -1

If Mid(tstr, i, tlen) = twhat Then
n = i
Exit For
End If
Next i

xLastInStr = n

End Function
 

Users who are viewing this thread

Back
Top Bottom