WORD
You can use the WORD function to parse a text item that is delimited by some character, such as a space or a comma.
WORD returns the characters between two user-defined separators within a text item. The separators are counted from left to right when the third argument is positive, and from right to left when the third argument is negative, enabling the function to search from either end of the item.
- Syntax:
WORD (single-text-expression , single-text-expression ,
single-integer-expression)- Meaning:
- WORD (text_to_search , word_separator , number_of_word_to_get)
- Returns:
- A single text item
WORD returns the characters (word) between the nth-1 and nth word_separator, where n corresponds to number_of_word_to_get.
Define the separator (word_separator) and specify the number of the occurrence of that separator. The WORD function returns the characters between the nth-1 and nth separators in the delimited text item.
The separator is case sensitive.
Examples
The following examples assume that a file exists named Letter with two text objects named Line1 and Line2:
Line1:Congratulations, Mr Brown! You're a winner!;
Line2:You may have already won 1 million dollars!;
- WORD ( Line1:Letter , " " ,
3 )
Returns:
Brown!
The exclamation point is returned because it is read as a character within the word before the separator (a space).
- WORD ( Line1:Letter , " " ,
6 )
Returns:
winner!
If the nth separator is missing and the nth-1 separator exists, the function returns the characters between the last separator and the end of the delimited text item. The separator is a space; "
winner!
" (including the exclamation point) is the sixth word. - WORD ( Line2:Letter , "!" ,
3 )
Returns "none"
Both nth and nth-1 separators are missing. In this example, there is only one separator, located at the end of the text object. As a result, there is no third word because the function sees everything before "!" as the first word.
- WORD ( Line1:Letter , " " ,
1 )
Returns:
Congratulations,
If n-1 = 0, the function returns the characters between the beginning of the delimited text item and the first separator.
- WORD ( Line1:Letter , " " ,
-1 )
Returns:
winner!
If n+1 = 0, then the function returns the characters between the end of the text item and the last separator.
Related functions
- FIND
- MID