Manual:DIL Manual/getwords()
Jump to navigation
Jump to search
getwords()
Function (stringlist). Splits a string into its words.
getwords(s : string)
Returns a stringlist with one entry per word of s, in order. Words are separated by spaces; any number of spaces counts as one separator, and no empty entries are made. s itself is not changed (unlike getword()).
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text to split. |
Returns
Stringlist: the words. Empty when s is "" or only spaces. It fails if s fails or is a string variable that has never had a value; assigning a failed list leaves the variable as it was.
Notes
- Only the space character separates words. Tabs and line breaks stay inside the words:
getwords("a\nb")is one entry. For lines, usesplit(text, "\n"), orsplit(text, "<br/>")for text kept as HTML. length()gives the number of words;words.[0]is the first.
Example
dilbegin integer count_words(s : string);
var
words : stringlist;
code
{
words := getwords(s);
return (length(words));
}
dilend
Counts the words in a string: " open the door " gives 3.