replaceword(
TEXT
,
OLDWORD
,
NEWWORD
)
The replaceword( function replaces a word with a new word.
Parameters
This function has three parameters:
text – is the item of text that contains the words you want to search for and replace.
oldword – the original word.
newword – the new word.
Description
This function replaces a word with a new word. Only entire words are replaced. The function is quite smart – it knows about punctuation, and it will match the capitalization of the word being replaced.
local mytext
mytext = "One, someone, one, (ONE), oneida."
replaceword(mytext,"one","uno") ☞ Uno, someone, uno, (UNO), oneida.
This function will only work for words that are either all lower case (three
), all upper case (THREE
) or with the first letter capitalized (Three
or Apple Computer
). It will not work for text that has other capitalizations, for example McConnell
(and by “not work”, we mean the text will not be replaced at all). Use the replacewordexact( function if the text has non-standard capitalization.
See Also
- after( -- extracts all text after a specified tag (sequence of characters).
- before( -- extracts all text before a specified tag (sequence of characters). If the tag doesn't exist the function returns "".
- extract( -- extracts a single data item from a text array, and can also be used to count the number of items in the array.
- firstline( -- extracts the first line from the text.
- firstword( -- extracts the first word from the text.
- lastline( -- extracts the last line from the text.
- lastword( -- extracts the last word from the text.
- left( -- extracts characters from the left edge of the text.
- nthline( -- extracts the nth line from the text.
- nthword( -- extracts a word from the middle of the text.
- randomline( -- returns a random line from multiple lines of text.
- randomword( -- returns a random word from a list of words.
- right( -- extracts characters from the right edge of the text.
- textafter( -- extracts the text after the tag.
- textbefore( -- extracts the text before the tag.
- trim( -- removes characters from the right edge of the text.
- trimleft( -- removes one or more characters from the left edge of the text.
History
10.0 | New | New in this version. |