string.lastWord

Syntax string.lastWord (string)

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

Action Extracts the last word from string. A word is defined as a string of characters terminated by the character currently defined as the wordChar. The last word is therefore the last string of characters in string following the last occurrence of wordChar.

Returns The resulting string.

Examples string.lastWord ("Eat a good lunch!")

   » lunch!

Note that the ending punctuation is included with string.lastWord. This example assumes wordChar is a space.

string.lastWord ("Coming-into-being is here.")

   » "here."

string.setWordChar ("-");
string.lastWord ("Here comes Coming-into-being.")

   » "being."

string.setWordChar ("");
s = "Eat a good lunch!";
string.firstWord (s) + " " + string.lastWord (s)

   » "Eat lunch!"

Notes The string returned by string.lastWord does not include the preceding word delimiter but does include any trailing punctuation.

See Also string.firstWord

string.getWordChar

string.setWordChar

Discuss