90个字符后的tcl拆分变量

时间:2017-09-13 15:41:42

标签: split tcl

我将变量中的文本添加到文件中,并在80个字符后分割到下一行。

bind pub "-|-" !maketext pub:textmaker
proc pub:textmaker { nick host handle channel arg } {

    set fid [open text.txt w]
    puts $fid "."
    puts $fid "asdflk asdkflasdfioasd fasdf as dfa sdf a sdf"   
    puts $fid "."
    puts $fid "$arg"    
    puts $fid "."
    puts $fid "."   
    close $fid
}

示例来自我希望添加的文字

这是一个变量:从“When”开始到结束是“opining”。

!maketext When Conan left NBC, Late night with jimmy Fallon was the only talk show that was left that was kinda Okay. However over the past year Jimmy has matured into a hilarious improviser along with Steve Higgins and their chemistry is amazing. Those two make the opining

如何使〜80个字符后的新行\ n。首先从例子中“谈话”,然后在“成熟”之后,接着在“惊人”之后。 ....

1 个答案:

答案 0 :(得分:2)

::textutil::adjust

很容易
% package require textutil

% set s {When Conan left NBC, Late night with jimmy Fallon was the only talk show that was left that was kinda Okay. However over the past year Jimmy has matured into a hilarious improviser along with Steve Higgins and their chemistry is amazing. Those two make the opining}

% ::textutil::adjust $s -length 80 -strictlength true
When Conan left NBC, Late night with jimmy Fallon was the only talk show that
was left that was kinda Okay. However over the past year Jimmy has matured into
a hilarious improviser along with Steve Higgins and their chemistry is amazing.
Those two make the opining

如果取消-strictlength选项或将其设置为false,该命令将允许单个单词超过限制。

文档: textutil (package)