2

次の文字列があります。

"name\r {} {} {} {} {} other_name other_name {} {} -600.0 {} {} 860.0 {} {} -"

(つまり、特殊文字を含む文字列: \r )。

この行を実行するjoinと、特殊文字が失われます。

仮定する:

set name "name\r {} {} {} {} {} other_name other_name {} {} -600.0 {} {} 860.0 {} {} -"

set name [join $name]

現在、名前から特殊文字が失われています (少なくとも\r)。

これを解決するには?

4

1 に答える 1

1

私はいくつかのことを試して、これを思いついた:

set name {name\r {} {} {} {} {} other_name other_name {} {} -600.0 {} {} 860.0 {} {} -}
# The braces prevent the substitution of \r

regsub -all {\\r} $name {\\\r} name
# This is a substitution using regexp to substitute all \r to \\r

set name [join $name]
# Returns: "name\r      other_name other_name   -600.0   860.0   -"

または、エスケープしたい文字がさらにある場合は、より一般的なものを使用してください。

regsub -all {\\} $name {\\\\} name

代わりは。

于 2013-05-08T16:28:17.003 に答える