set data [open file.txt r]
set lines [split $data]
set num [llength $lines]
for {set i 0} {$i<=$num } {incr i +1 } {
set linei [lindex $lines $i]
set line [split $linei " " ]
set a0 [lindex $line 0] #再对列表line进行处理貌似解决问题
set output [open file.txt r] #打开读入文件set data [read $output]
set lines [split $data]
set num [llength $lines]
for {set i 0} {$i<=$num } {incr i +1 } {
set linei [lindex $lines $i]
set line [split $linei " " ]
set a0 [lindex $line 0] #再对列表line进行处理貌似解决问题
参考这段代码:
(贴上来乱码了,你看https://www.tcl.tk/man/tcl8.6/TclCmd/regsub.htm的末尾吧。)
Convert all non-ASCII and Tcl-significant characters into \u escape sequences by using regsub and subst in combination:
# This RE is just a character class for almost everything "bad"set RE {[][{};#\\\$ \r\t\u0080-\uffff]}# We will substitute with a fragment of Tcl script in bracketsset substitution {[format \\\\u%04x [scan "\\&" %c]]}# Now we apply the substitution to get a subst-string that# will perform the computational parts of the conversion. Note# that newline is handled specially through string map since# backslash-newline is a special sequence.set quoted [subst [string map {\n {\\u000a}} \ [regsub -all $RE $string $substitution]]]