I need to strip leading and trailing whitespace from a string in TCL. How?
How to strip whitespace in string in TCL?
Asked Answered
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
Here'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
–
Timehonored try this. this will remove all the withe spaces
[string map {" " ""} $a];
a is your string
He only wants to strip leading and tailing whitespace. Also you don't remove other types of whitespace, like tabulator, newline... –
Hobbism
© 2022 - 2024 — McMap. All rights reserved.
string trimleft
andstring trimright
when you only want to trim one end. – Scaremonger