Recursive GetPart function (1 Viewer)

Status
Not open for further replies.

Guus2005

AWF VIP
Local time
Today, 20:13
Joined
Jun 26, 2007
Messages
2,641
This function returns the n-th string

Code:
Public Function GetPart(strString As String, strSep As String, intPart As Integer) As String
   Dim intFound As Integer
   Dim intNext  As Integer
   
   intFound = InStr(1, strString, strSep)
   If intFound > 0 Then
      If intPart = 1 Then
         GetPart = Mid$(strString, 1, intFound - 1)
      Else 'intPart > 1
         GetPart = GetPart(Mid$(strString, intFound + 1), strSep, intPart - 1) 'recursive
      End If
   Else 'intFound = 0, no occurence of seperator so return complete string
      GetPart = strString
   End If
   
End Function
 
Status
Not open for further replies.

Users who are viewing this thread

Top Bottom