CodeItBetter Programming Another VB Programming Blog

How to returns the Nth token in a string. Ex: GetWord(“This is a test.”, ” “, 2) = “is”

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
'String Manipulation - How to returns the Nth token in a string. Ex: GetWord("This is a test.", " ", 2) = "is"
Option Explicit
 
Public Function GetWord(ByVal strExpression As String, ByVal sToken As String, _
    ByVal Nth As Integer) As String
    Dim strWords() As String
    strWords = Split(strExpression, sToken)
    If Nth - 1 <= (UBound(strWords) - LBound(strWords) + 1) Then
        GetWord = strWords(Nth - 1)
    End If
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.