How to replace particular character in string with tcl script?

Harshad_Dinfi picture Harshad_Dinfi · May 2, 2016 · Viewed 36.7k times · Source
set some_string "Name/is/ComplexSTRUCTUre" 

convert this string to,

some_string = "Name/is/ComplexSTR.CTUre" 

i.e replacing first "U" to "."

Answer

mf_starboi_8041 picture mf_starboi_8041 · May 2, 2016

Try This,

set replaced_string [regsub "U" $some_string "."]
puts $replaced_string

Another Option,

set pos [string first "U" $some_string]
set replaced_string [string replace $some_string $pos $pos "."]
puts $replaced_string

Here your "Name/is" portion should not contain any "U"

More information can be found here tcl string replacement