TCL 在字符串中设置特殊字符 [英] TCL set Special Characters in a string

查看:71
本文介绍了TCL 在字符串中设置特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 TCL 中将以下错误消息设置为变量并与来自网络交换机的错误消息进行比较,绕过特殊字符

I want to set in TCL the below error message as a variable and compare with the error message from a network switch, by-passing the special characters

使用 [slot/port] 或 ["portname"] 或 [slot/*] 或 [*].

Use [slot/port] or ["portname"] or [slot/*] or [*].

我是这样试的

set x "Use \[slot/port] or \["portname"] or \[slot/\*] or \[\*]."

但我在运行脚本时收到以下消息:

but I am getting the following message while running my script:

引号后的额外字符执行时

extra characters after close-quote while executing

请帮忙.谢谢!

推荐答案

如果使用双引号,还必须转义内部"引号:

If you use double quotes, you also have to escape "inner" quotes:

set x "Use \[slot/port] or \[\"portname\"] or \[slot/*] or \[*]."

或者使用大括号避免完全转义

Or use braces and avoid escaping altogether

set x {Use [slot/port] or ["portname"] or [slot/*] or [*].}

参见Tcl 的 12 条语法规则,数字 4 和 6

See Tcl's 12 syntax rules, numbers 4 and 6

这篇关于TCL 在字符串中设置特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆