Access/VBA Library

GetWord

Returns the blank-delimited word specified by a wordnumber from a string.

Syntax

GetWord( aString [, wordNo] )
Parameters
Name Type Description
aString String Required. The string to get the word from.
wordNo Long Optional. The number of the requested word.
Default: 1
Return value

String : The word with number wordNo from aString. When wordNo is out of range an empty string is returned.

Code
Public Function GetWord(aString As String, Optional ByVal wordNo As Long = 1) As String
    Dim words: words = Tokenizer(aString, " ")
    
    If aString = "" Then Exit Function
    If wordNo > LBound(words) And wordNo <= UBound(words) + 1 Then
        GetWord = words(wordNo - 1)
    End If
    
End Function

Stringtag:String

Remarks

  • The index of the first word is 1.

See also

  • Tokenizer