如何将ASCII控制字符插入TCL字符串中?

发布于 2025-02-07 17:50:25 字数 136 浏览 4 评论 0 原文

我需要创建一个包含ASCII控制字符的TCL脚本。 但我只对将“启动文本”值2和“文本末端”放入值3。

这是从ASCII表中的这些字符的完整列表, net/x9e5b.png“ rel =“ nofollow noreferrer”>

I need to create a TCL script that contains ASCII control characters. This is the full list of these characters from the ASCII table but I am only interested in putting in the "start of text" value 2 and "end of text" value 3.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2025-02-14 17:50:25

您可以通过编写 \ xnn 在字符串中输入十六进制代码,其中 nn 是代码,例如,

set start_of_text "\x02"
set end_of_text "\x03"

请参见

You can enter a hex code in a string by writing \xnn where nn is the code, e.g.

set start_of_text "\x02"
set end_of_text "\x03"

See the documentation at https://www.tcl-lang.org/man/tcl8.6/TclCmd/Tcl.htm#M27

送舟行 2025-02-14 17:50:25

您也可以使用格式%C 代码(如果您在运行时都不知道相关号码,这可能会更有用,因为它在变量中或其他):

set ascii(STX) [format %c 2]
set ascii(ETX) [format %c 3]

You can also use format with the %c code (which might be more useful if you don't know the relevant number until run-time because it's in a variable or whatever):

set ascii(STX) [format %c 2]
set ascii(ETX) [format %c 3]
涫野音 2025-02-14 17:50:25

如果我要以控制序列(通常是针对使用着色之类的东西)包装文本,那么我将做一个工作以完成工作:

proc wrapped {string} {
    # These use Unicode escapes
    return "\u0002$string\u0003"
}

puts [wrapped "this is some test text"]

If I'm going to be wrapping text in a control sequence (often for things like applying a colouring) then I'll make a procedure to do the job:

proc wrapped {string} {
    # These use Unicode escapes
    return "\u0002$string\u0003"
}

puts [wrapped "this is some test text"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文