I need to strip leading and trailing whitespace from a string in TCL. How?
As its name implies, trimright is used to trim trailing whitespace or other characters as specified. The trimright keyword will return string with all trailing whitespace trimmed if no characters are provided. If the optional characters are not specified only will be removed.
trim() The trim() method removes whitespace from both ends of a string and returns a new string, without modifying the original string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.)
String result = str. trim(); The trim() method will remove both leading and trailing whitespace from a string and return the result.
The string command Use 'first' or 'last' to look for a substring. The return value is the index of the first character of the substring within the string. The 'string match' command uses the glob-style pattern matching like many UNIX shell commands do. Matches any number of any character.
Try this -
string trim string ?chars?
Returns a value equal to string except that any leading or trailing characters from the set given by chars are removed. If chars is not specified then white space is removed (spaces, tabs, newlines, and carriage returns).
Original Source :- http://wiki.tcl.tk/10174
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With