I need to strip leading and trailing whitespace from a string in TCL. How?
Asked
Active
Viewed 2.6k times
2 Answers
15
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

Community
- 1
- 1

Sachin Shanbhag
- 54,530
- 11
- 89
- 103
-
2There's also `string trimleft` and `string trimright` when you only want to trim one end. – Donal Fellows Jan 11 '11 at 13:33
-
2Here's an example how the *chars* argument works: trim (english) vowels from the left and right of a string: `set str "each patio"; puts [string trim $str "aeiou"]` outputs `ch pat` – glenn jackman Jan 11 '11 at 16:15
0
try this. this will remove all the withe spaces
[string map {" " ""} $a];
a is your string

worldofjr
- 3,868
- 8
- 37
- 49
-
2He only wants to strip leading and tailing whitespace. Also you don't remove other types of whitespace, like tabulator, newline... – Johannes Kuhn Dec 31 '15 at 16:27