Clovertech
› Clovertech Forums › Read Only Archives › Cloverleaf › Tcl Library › String Manipulations
What is the best method to replace the second character in a variable string to a last character?
Example
From : XZ94363459445
To: X94363459445Z
This would be my way of doing this:
set test “XZ94363459445” set result “[string range $test 0 0][string range $test 2 end][string range $test 1 1]”
Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands
Agreed.
-- Max Drown (Infor)
C’mon Max, how about a regular expression: 😀
regsub — {(w)(w)(.*$)} test {132} result
or (two commands instead of three)
set result [string replace “$test[string index $test 1]” 1 1]
Just making the point that there are many ways to accomplish the same thing. I can’t really say one way is better than the other 😉
C’mon Max, how about a regular expression:
Thanks a lot guys for your quick response.