DELWORD | Removes (deletes) one or more words from a string. |
FIND | Searches a string for a phrase, and returns its position within the string. |
JUSTIFY | Formats the words in a string justified to a specific length. |
SPACE | Formats the words in a string with pad characters between each word. |
SUBWORD | Excerpts one or more words from a string. |
WORD | Excerpts one word from a string. |
WORDINDEX | Returns the character position of a word within a string. |
WORDLENGTH | Returns the length of a word within a string. |
WORDPOS | Searches a string for a phrase, and returns its position within the string. |
WORDS | Counts the number of words in a string. |
Returns a string with one or more words (and all blank space between them) removed.
newstring = DELWORD(string, start, length)
string is the original string (from which to remove words).
start is which word number to start removing from, where 1 would be to start removing at the first word in the string. If there are less words in the string than start, then the original string is returned, unchanged. start cannot be 0 or negative, nor have a fractional component -- it must be a positive whole number.
length is the number of words to be removed, starting at (ie, including) the word numbered start. If length is omitted, the default is to remove all words from the start word to the end of the string. If length is 0, no words are removed. length cannot be negative, nor have a fractional component -- it must be a positive integer.
A copy of the original string without the removed words.
Any spaces immediately after the last removed word are also deleted. But the spaces before the first removed word are retained.
It is not an error if start or length (or a combination of them) refers to more words than string actually contains.
The original string is not altered. Only the returned value from DELWORD has words removed.
DELWORD('This is a test', 3) |
'This is ' |
DELWORD('This is a test', 2, 1) |
'This a test' |
DELWORD('This is a test', 2, 5) |
'This ' |
DELWORD('This is a test', 1, 3) |
'test' /*No leading space*/ |
DELSTR, OVERLAY, CHANGESTR, STRIP
Searches a string for a phrase (consisting of one or more words), and if the phrase is found, returns the word position where that phrase starts within the string.
position = FIND(string, phrase, start)
phrase is the group of words to search for (within string).
string is the string to search (for phrase).
start is which word number to start searching from, where 1 would be to start searching at the first word in string. If omitted, the default is to start searching from the first word in the string. If there are less words in the string than start, then 0 is returned, to indicate that the phrase was not found. start must not be negative, nor have a fractional component -- it must be a positive whole number.
The word number where the specified phrase started within the string (where 1 means that the phrase is found starting at the very first word in the string), or 0 if no such phrase is in the string.
This is identical to the WORDPOS() function, except that the first two arguments are reversed. Some interpreters do not implement FIND(), so it is best to use WORDPOS() instead.
Returns a string justified with pad characters between each word. Any blank space originally between each word is replaced by the pad characters.
justified = JUSTIFY(string, length, padchar)
string is the original string (to justify).
length is the desired length of the justified string. If length is larger than the actual number of characters in the string, then padchars are inserted between each word in order to evenly space the words to fit within length. If length is smaller than the actual number of characters in the string, then characters are truncated from the end of the string to fit length.
padchar is the character to use for padding. If padchar is omitted, the default is a space character.
A copy of the original string with words justified to fit exactly length characters.
The original string is not altered. Only the returned value from JUSTIFY is justified.
JUSTIFY('Hi there, all', 20) |
'Hi there, all' |
JUSTIFY('Hi there, all', 10) |
'Hi there, ' |
Returns a string formatted with pad characters between each word. Any blank space originally between each word is replaced by the pad characters.
formatted = SPACE(string, length, padchar)
string is the original string (to format).
length is the number of padchars to be inserted between each word. If length is omitted, the default is one padchar between each word. If length is 0, all spaces are removed.
padchar is the character to use for padding. If padchar is omitted, the default is a space character. (ie, The original padchars between each word are replaced by length number of padchars).
A copy of the original string with the spaces between words replaced by the padchars.
The original string is not altered. Only the returned value from SPACE is formatted.
SPACE(' Foo bar ') |
'Foo bar' |
SPACE(' Foo bar ', 2) |
'Foo bar' |
SPACE(' Foo bar ', , '*') |
'Foo*bar' |
SPACE('Foo bar', 3, '-') |
'Foo---bar' |
SPACE('Foo bar', 0) |
'Foobar' |
JUSTIFY, EXPAND, STRIP, TRANSLATE
Excerpts one or more words (and all blank space between them) from a string, and returns that excerpt.
excerpt = SUBWORD(string, start, length)
string is the original string (from which to excerpt words).
start is which word number to start the excerpt from, where 1 would be to start the excerpt at the first word in the string. If there are less words in the string than start, then an empty string is returned. start cannot be 0 or negative, nor have a fractional component -- it must be a positive whole number.
length is the number of words to be excerpted, starting at the word numbered start. If length is omitted, the default is to excerpt all words from the start word to the end of the string. If length is 0, no words are excerpted. length cannot be negative, nor have a fractional component -- it must be a positive integer.
A string containing the excerpted words (and all spaces between them).
Spaces before and after the excerpted words are trimmed.
It is not an error if start or length (or a combination of them) refers to more words than string actually contains.
The original string is not altered.
SUBWORD('To be or not to be', 4) |
'not to be' |
SUBWORD('To be or not to be', 4, 2) |
'not to' |
SUBWORD('To be or not to be', 4, 5) |
'not to be' |
SUBWORD('To be or not to be', 1, 3) |
'To be or' |
Excerpts one word from a string, and returns that word without any leading or trailing spaces.
word = WORD(string, wordnum)
string is the original string (from which to excerpt the word).
wordnum is which word number to excerpt, where 1 would be the first word in the string. If there are less words in the string than wordnum, then an empty string is returned. wordnum must not be negative, nor have a fractional component -- it must be a positive whole number.
The excerpted word.
This is essentially the same as SUBWORD, except that it extracts only one word, and therefore has no length arg.
The original string is not altered.
WORD('To be or not to be', 3) |
'or' |
WORD('To be or not to be', 4) |
'not' |
WORD('To be or not to be', 8) |
'' /* An empty string */ |
Returns the character position of a particular word within a string.
position = WORDINDEX(string, wordnum)
string is the original string (from which to excerpt the word).
wordnum is which word number to query, where 1 would be the first word in the string. If there are less words in the string than wordnum, then 0 is returned. wordnum must not be negative, nor have a fractional component -- it must be a positive whole number.
The character position of the specified word within the string (where 1 means that the word begins at the very first character in the string), or 0 if no such word is in the string.
WORDINDEX('To be or not to be', 3) |
7 |
WORDINDEX('To be or not to be', 4) |
10 |
WORDINDEX('To be or not to be', 8) |
0 |
Returns a count of how many characters are in a particular word within a string.
length = WORDLENGTH(string, wordnum)
string is the original string (from which to excerpt the word).
wordnum is which word number to query, where 1 would be the first word in the string. If there are less words in the string than wordnum, then 0 is returned. wordnum must not be negative, nor have a fractional component -- it must be a positive whole number.
A count of how many characters are in the specified word within the string, or 0 if no such word is in the string.
Leading and trailing spaces around the word are not counted.
WORDLENGTH('To be or not to be', 3) |
2 |
WORDLENGTH('To be or not to be', 4) |
3 |
WORDLENGTH('To be or not to be', 8) |
0 |
Searches a string for a phrase (consisting of one or more words), and if the phrase is found, returns the word position where that phrase starts within the string.
position = WORDPOS(phrase, string, start)
phrase is the group of words to search for (within string).
string is the string to search (for phrase).
start is which word number to start searching from, where 1 would be to start searching at the first word in string. If omitted, the default is to start searching from the first word in the string. If there are less words in the string than start, then 0 is returned, to indicate that the phrase was not found. start must not be negative, nor have a fractional component -- it must be a positive whole number.
The word number where the specified phrase started within the string (where 1 means that the phrase is found starting at the very first word in the string), or 0 if no such phrase is in the string.
This is similiar to POS(), except WORDPOS() searches for a phrase, and POS() searches for a substring. Searching for a phrase differs from searching for a substring in one significant way; the number of spaces separating the words in a phrase have no effect upon the search. For example,
"is a"would be considered a phrase within
"This is a string". (Notice that there are 2 spaces between "is" and "a" in our phrase, but only one space in the string. The difference in spaces is irrelevant to the match). But
"is a""This is a string", due to the different amount of space characters. So, WORDPOS() would be used if you need to search for a group of words regardless of the number of spaces between each word. POS() would be used if the amount of space between each word is important.
WORDPOS(' or not ', 'to be or not to be') |
3 |
WORDPOS('not to', 'to be or not to be') |
4 |
WORDPOS('to be', 'to be or not to be') |
1 |
WORDPOS('to be', 'to be or not to be', 3) |
6 |
POS, LASTPOS, COUNTSTR, ABBREV
Returns a count of how many words are in a string.
count = WORDS(string)
string is the string (containing the words to count).
A count of how many words are in the string, or 0 if no words are in the string. Each word is separated by one or more spaces.
WORDS('To be or not to be') |
5 |
WORDS('Hello, my dear.') |
3 |
WORDS(' ') |
0 |