The following built-in functions operate upon a string that contains one or more words. Each word (within the string) is separated from the other words by one or more space characters (or any other character regarded as a space such as a TAB character, newline character. form feed, etc).

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.


DELWORD

Returns a string with one or more words (and all blank space between them) removed.

Synopsis
newstring = DELWORD(string, start, length)

Args

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.

Returns

A copy of the original string without the removed words.

Notes

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.

Examples

Example use
Return value
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*/

See also

DELSTR, OVERLAY, CHANGESTR, STRIP


FIND

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.

Synopsis
position = FIND(string, phrase, start)

Args

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.

Returns

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.

Notes

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.

See also

WORDPOS


JUSTIFY

Returns a string justified with pad characters between each word. Any blank space originally between each word is replaced by the pad characters.

Synopsis
justified = JUSTIFY(string, length, padchar)

Args

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.

Returns

A copy of the original string with words justified to fit exactly length characters.

Notes

The original string is not altered. Only the returned value from JUSTIFY is justified.

Examples

Example use
Return value
JUSTIFY('Hi there, all', 20)
'Hi     there,    all'
JUSTIFY('Hi there, all', 10)
'Hi there, '

See also

STRIP, SPACE, EXPAND


SPACE

Returns a string formatted with pad characters between each word. Any blank space originally between each word is replaced by the pad characters.

Synopsis
formatted = SPACE(string, length, padchar)

Args

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).

Returns

A copy of the original string with the spaces between words replaced by the padchars.

Notes

The original string is not altered. Only the returned value from SPACE is formatted.

Examples

Example use
Return value
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'

See also

JUSTIFY, EXPAND, STRIP, TRANSLATE


SUBWORD

Excerpts one or more words (and all blank space between them) from a string, and returns that excerpt.

Synopsis
excerpt = SUBWORD(string, start, length)

Args

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.

Returns

A string containing the excerpted words (and all spaces between them).

Notes

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.

Examples

Example use
Return value
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'

See also

SUBSTR, LEFT, RIGHT


WORD

Excerpts one word from a string, and returns that word without any leading or trailing spaces.

Synopsis
word = WORD(string, wordnum)

Args

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.

Returns

The excerpted word.

Notes

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.

Examples

Example use
Return value
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 */


WORDINDEX

Returns the character position of a particular word within a string.

Synopsis
position = WORDINDEX(string, wordnum)

Args

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.

Returns

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.

Examples

Example use
Return value
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


WORDLENGTH

Returns a count of how many characters are in a particular word within a string.

Synopsis
length = WORDLENGTH(string, wordnum)

Args

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.

Returns

A count of how many characters are in the specified word within the string, or 0 if no such word is in the string.

Notes

Leading and trailing spaces around the word are not counted.

Examples

Example use
Return value
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

See also

LENGTH


WORDPOS

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.

Synopsis
position = WORDPOS(phrase, string, start)

Args

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.

Returns

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.

Notes

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.

Examples

Example use
Return value
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

See also

POS, LASTPOS, COUNTSTR, ABBREV


WORDS

Returns a count of how many words are in a string.

Synopsis
count = WORDS(string)

Args

string is the string (containing the words to count).

Returns

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.

Examples

Example use
Return value
WORDS('To be or not to be')
5
WORDS('Hello, my dear.')
3
WORDS(' ')
0