TCL:反斜杠问题(regsub) [英] TCL: Backslash issue (regsub)
问题描述
我在尝试读取像 \\server\directory
这样的列表的成员时遇到问题当我尝试使用 lindex
命令获取此变量时出现问题,该命令继续进行 TCL 替换,因此结果是:
I have an issue while trying to read a member of a list like \\server\directory
The issue comes when I try to get this variable using the lindex
command, that proceeds with TCL substitution, so the result is:
\serverdirectory
然后,我想我需要使用 regsub
命令来避免反斜杠替换,但我没有得到正确的过程.
Then, I think I need to use a regsub
command to avoid the backslash substitution, but I did not get the correct proceedure.
我想要的一个例子应该是:
An example of what I want should be:
set mistring "\\server\directory"
regsub [appropriate regular expresion here]
puts "mistring: '$mistring'" ==> "mistring: '\\server\directory'"
我已经检查了一些关于此的帖子,并保持 \\
没问题,但是在尝试始终保持单个 \
后跟任何其他内容时仍然遇到问题可以来到这里的角色.
I have checked some posts around this, and keep the \\
is ok, but I still have problems when trying to keep always a single \
followed by any other character that could come here.
更新:具体例子.我实际上想要保留的是列表中元素的初始格式.该列表由外部应用程序接收.原来的代码是这样的:
UPDATE: specific example. What I am actually trying to keep is the initial format of an element in a list. The list is received by an outer application. The original code is something like this:
set mytable $__outer_list_received
puts "Table: '$mytable'"
for { set i 0 } { $i < [llength $mitabla] } { incr i } {
set row [lindex $mytable $i]
puts "Row: '$row'"
set elements [lindex $row 0]
puts "Elements: '$elements'"
}
这个的输出,在这种情况下是:
The output of this, in this case is:
Table: '{{
address \\server\directory
filename foo.bar
}}'
Row: '{
address \\server\directory
filename foo.bar
}'
Elements: '
address \\server\directory
filename foo.bar
'
所以我尝试获取地址的值(在这种特定情况下,\\server\directory
)以便将其写入配置文件,同时保留原始格式和数据.我希望这能澄清问题.
So I try to get the value of address (in this specific case, \\server\directory
) in order to write it in a configuration file, keeping the original format and data.
I hope this clarify the problem.
推荐答案
如果您不想替换,请将有问题的字符串放在花括号内.
If you don't want substitutions, put the problematic string inside curly braces.
% puts "\\server\directory"
\serverdirectory
这不是你想要的.但是
% puts {\\server\directory}
\\server\directory
根据您的需要.
这篇关于TCL:反斜杠问题(regsub)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!