How to change lowercase to uppercase in Tcl?

I am trying to write all lowercase letters in uppercase in a file using character classes:

regsub -all { [:lower:] } $f { [:upper:] } f 

but he does not perform the replacement.

+4
source share
2 answers

Just read the file in line and use string toupper . Then write it back to the file.

 set fp [open "somefile" r] set file_data [read $fp] close $fp set file_data [string toupper $file_data] set fp [open "somefile" "w"] puts -nonewline $fp $file_data close $fp 
+6
source

Yes, the above will work like a charm.

 set f [string toupper $f] 

f is a list or string. If you want to work with files, as usual, read from a file and write.

If you just want to use regsub, try

 set f "this is a line" regsub -all {.*} $f {[string toupper {&}]} f set f [subst -nobackslashes -novariables $f] 

now your content in f is uppercase.

note: it looks long, but is useful when selecting only a specific text, which should be top or bottom.

Thanks,

+2
source

All Articles