Tcl 如何有效地分割线?
我想按Tcl 如何有效地分割线?,tcl,Tcl,我想按\t=或, 我已尝试使用: set line [split $line" \t=,"] set result {} foreach element $line { if { $element != {} } { lappend result $element } } 线条看起来像: name1 name2 name3 floating_point_number1, floating_point_number2 或 但是它看起来很慢。 如何更改代码以提
\t
=或,
我已尝试使用:
set line [split $line" \t=,"]
set result {}
foreach element $line {
if { $element != {} } {
lappend result $element
}
}
线条看起来像:
name1 name2 name3 floating_point_number1, floating_point_number2
或
但是它看起来很慢。
如何更改代码以提高效率?您可能需要查看tcllib中的模块
% set s "this\tis=a,line=,\twith separators="
this is=a,line=, with separators=
% package require textutil::split
0.7
% textutil::split::splitx $s {[[:blank:]=,]}
this is a line {} {} {with separators} {}
如果您希望避免的是空元素,那么tcllib包会有所帮助
% package req struct::list
1.7
% set l [textutil::split::splitx $s {[[:blank:]=,]}]
this is a line {} {} {with separators} {}
% struct::list filterfor field $l {[llength $field] > 0}
this is a line {with separators}
您可能希望查看tcllib中的模块
% set s "this\tis=a,line=,\twith separators="
this is=a,line=, with separators=
% package require textutil::split
0.7
% textutil::split::splitx $s {[[:blank:]=,]}
this is a line {} {} {with separators} {}
如果您希望避免的是空元素,那么tcllib包会有所帮助
% package req struct::list
1.7
% set l [textutil::split::splitx $s {[[:blank:]=,]}]
this is a line {} {} {with separators} {}
% struct::list filterfor field $l {[llength $field] > 0}
this is a line {with separators}
请显示一些示例输入。请显示一些示例输入。将
\t
更改为[:blank://code>以匹配任何水平空白。将\t
更改为[:blank://code>以匹配任何水平空白。