string.nthWord

Syntax string.nthWord (string, index)

Params string is the string from which you wish to extract a word.

index is a number indicating the 1-based index position of the word within string you wish to extract.

Action Extracts from string the single word at position index with words defined as strings of characters delimited by the current wordChar.

Returns The indicated word.

Examples string.nthWord ("Eat a good lunch!", 3)

   » good

string.nthWord ("Coming-into-being is here.", 3)

   » here.

Note that the terminating punctuation is included in the return value.

string.nthWord ("Coming-into-being is, at last, here.", 4)

   » last,

Note that the internal punctuation prior to wordChar is included in the return value.

string.nthWord ("Programming after midnight is normal.", 99)

   » ""

This example returns the empty string because index is larger than the number of words in string, which in this case is 5 (see "Notes," below).

ch = string.getWordChar ();
string.setWordChar ('.');
word = string.nthWord ("people.DW.notepad", 2);
string.setWordChar (ch);
word
DW

Note that since the period is the word delimiter, it is not considered trailing punctuation and is therefore not part of the word.

Notes If index < 1, or if index > the number of words in string, this verb returns the empty string.

See Also string.nthField

Discuss