ztcl::text words
Gives the list of the words of a string.
ztcl::text words ?-all? STRING
Description
Gives the word segments of UAX #29 that have a letter or a number. Spaces and punctuation are segments of their own, and only -all keeps them. The rules keep can't, e.g, 3.14, and example.com in one segment.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| STRING | string | required | The string to cut. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
-all | flag | none | Keeps each segment, also the spaces and the punctuation. |
-all
Keeps each segment, also the spaces and the punctuation.
Gives each segment of STRING, so join of the list gives STRING again.
% ztcl::text words -all "a, b"
a , { } b
% join [ztcl::text words -all "Hi, you."] ""
Hi, you.% ztcl::text words -- x
bad option "--": must be -all
-errorcode TCL LOOKUP INDEX optionReturns
A list of strings.
Examples
Each example of this page runs after package require ztcl::text.
% ztcl::text words "Hello, world."
Hello world
% ztcl::text words "Don't stop: 3.14 is pi."
Don't stop 3.14 is pi
% ztcl::text words "see example.com, e.g."
see example.com e.g
% ztcl::text words ""
Errors
% ztcl::text words
wrong # args: should be "ztcl::text words ?-all? string"
-errorcode TCL WRONGARGS
% ztcl::text words -bogus x
bad option "-bogus": must be -all
-errorcode TCL LOOKUP INDEX option
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1
- Compute cost
- One compute unit for each 4,096 bytes of the string.