string reverse
Gives the characters of a string in the reverse order.
string reverse STRING
string reverse -grapheme STRING
Description
Gives the characters of STRING from the last to the first. A combining mark moves to the other side of its letter, so text with accents can change its look. -grapheme keeps each grapheme cluster whole.
With one argument, string reverse -grapheme reverses the text -grapheme.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| STRING | string | required | The text to reverse. |
Options
| Option | Type | Default | Summary |
|---|---|---|---|
-grapheme | flag | none | Reverses the order of the grapheme clusters, each with its characters in order. |
-grapheme
Reverses the order of the grapheme clusters, each with its characters in order.
Reverses the order of the grapheme clusters of STRING. The code points of each cluster keep their order, so a letter keeps its accent and a flag stays the same flag.
% string equal [string reverse -grapheme "aé"] "éa"
1
# With no option, the accent moves before its letter.
% string equal [string reverse "aé"] "́ea"
1
% string reverse -grapheme "\U1F1FA\U1F1F8\U1F1EC\U1F1E7"
🇬🇧🇺🇸% string reverse -grapheme a b
wrong # args: should be "string reverse string"
-errorcode TCL WRONGARGSReturns
The new string.
Examples
% string reverse abc
cba
% string reverse ""
% string reverse -grapheme
emehparg-
Errors
% string reverse
wrong # args: should be "string reverse string"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1