字符串:
{ii= 10 } & {jj= 2 }
我需要:
ii= 10 & jj= 2
我试过了:
string trim
,string replace
,lreplace
,
他们不适合我。
答案 0 :(得分:1)
如果你有
set x "{ii= 10 } & {jj= 2 }"
你可以做到
string map {\{ {} \} {}} $x
# -> ii= 10 & jj= 2
即。用空字符串替换文字的左右括号。
但是你的字符串实际上看起来很像列表的字符串表示,自动插入大括号来保留空格。使用它作为列表,您需要做的就是
join $x
# -> ii= 10 & jj= 2
使用string trim
不起作用,因为它只会删除字符串末尾的字符:
string trim $x \{\}
# -> ii= 10 } & {jj= 2
在这种情况下,string replace
命令太多了。
lreplace
命令适用于列表元素,而不适用于字符串中的字符。
答案 1 :(得分:0)
这应该有效:
% set x "{ii= 10 } & {jj= 2 }"
{ii= 10 } & {jj= 2 }
% regsub -all {\{|\}} $x ""
ii= 10 & jj= 2
在这里,它只删除所有花括号并替换为空字符串 - 就像删除它们一样