I am trying to regsub all lower case letters to upper case in a file using character classes:
regsub -all { [:lower:] } $f { [:upper:] } f
but it doesn't do the substitution.
Just read the file into a string and use string toupper. Then write it back out to a 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
yes, above will work like charm.
set f [string toupper $f]
f is some list or string. If you want file operations, as usual read from file and write .
Although if you just want to use regsub, give this a try
set f "this is a line"
regsub -all {.*} $f {[string toupper {&}]} f
set f [subst -nobackslashes -novariables $f]
now your contents in f is uppercased.
note: it looks like long way but useful when selecting just particular text to be upper or lowercased
Thanks,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With