About
All string manipulation are made with the tcl command string
A string is enclosed with double quote and not with single quote. See string_length example.
Articles Related
Command Example
string length
> string length '123'
5
> string length "123"
3
string last
> string index "123456" end
6
> string index "123456" end-1
5
> string index "123456" 0
1
> string index "123456" 1
2
Range Manipulation
string range
> string range "123456" 0 1
12
> string range "123456" 4 5
56
> string range "123456" 2 5
3456
string replace
> string replace "12pa56" 2 3 "34"
123456
Trim
string trimright
> string trimright "1123____" "_"
1123
Advanced Examples
How to suppress 4 characters on the right side ?
> set Vs_String "123456789"
123456789
> set Vn_Length [string length $Vs_String]
9
> set Vn_First [expr $Vn_Length - 4]
5
> set Vn_Last [expr $Vn_Length - 1]
8
> set Vs_String [string replace $Vs_String $Vn_First $Vn_Last "" ]
12345
> string length $Vs_String
5