** Description ** Returns a value equal to ''string'' except that any leading or trailing characters that occur in ''chars'' are removed. <
> If ''chars'' is not specified then white space is removed (spaces, tabs, newlines, and carriage returns). '''`[string] trim`''' removes characters from the beginning and end of a string. ** Synopsis ** : '''string trim''' ''string ?chars?'' ** Demo ** ====== # http://ideone.com/IX2f6Y set s1 " Hello " set s2 [string trim $s1] puts "<$s1> <$s2>" # set s1 "*** Hello_###" set s2 [ string trim $s1 "*#_" ] puts "<$s1> <$s2>" #. ====== '''Result:''' ======none < Hello > <*** Hello_###> < Hello> ====== ** See Also ** * [string map]: Replace substrings in a string. * [string] : all the other "string"-commands * [Trimming indentation]: * [textutil%|%textutil]: Provides [regular expressions%|%regular expression] variants of the `string trim` commands, as well as `trimPrefix` an `trimEmptyHeading`. ** What Constitutes Whitespace ** See [TIP] [http://www.tcl.tk/cgi-bin/tct/tip/318.html%|%#318: Extend Default Whitespace in 'string trim' Beyond ASCII]. [escargo] 2008-06-02: This also related to behavior discussed in [comp.lang.tcl] with the subject, "string trim not trimming special space characters" (starting on 2008-03-04). The characters removed by `string trim ''string''` (with no ''chars'' argument) are '''not''' all the ones for which `[string is] space ''char''` returns `1`. I think the [TIP] should also include Unicode nonbreaking spaces. [LV]: You could either update the TIP page with your concerns, or post a comment over on the [TCT] mailing list. [MiHa] 2015-05-17: As I already ranted, missing examples are a common shortcoming in the docs. <
> As an example, how I would like examples done (here in the wiki, as well as in the help-system <
> that comes with the tcl/tk-installation, I added a demo-section, <
> with a link to an online-compiler, where this example can be seen "live". <> Tcl syntax help | Command | String Processing