This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Why is it so difficult to compare/catch [ and ] in tcl ... h

Old posts that have not been replied to for several years.
Locked
k
kapot

Post by kapot »

anyone know how to "catch" character [ and ] ?

I want to make a function "if there is [ and ] return 1"

tclsh
% set a x
x
% set b x
x
% string match $a $b
1
% set a "*[*]*"
*[*]*
% set b "[]"
[]
% string match $a $b
0
% set b "["
[
% string match $a $b
0
%
M
Mordred

Post by Mordred »

if {([string match "]" "$var"]) || ([string match "[" "$var"])} {return 1} {return 0}

in short, enclose the brackets in quotes in your string match and that should identify it as a string and not a tcl bracket.

<font size=-1>[ This Message was edited by: Mordred on 2002-05-02 12:57 ]</font>
P
Petersen
Owner
Posts: 685
Joined: Thu Sep 27, 2001 8:00 pm
Location: Blackpool, UK

Post by Petersen »

no
if {[string match *\[*\]* $var]} {
return 1
} else {
return 0
}


the characters [ and ] parsed by the string command as metacharacters, thus the double escapeage

<font size=-1>[ This Message was edited by: Petersen on 2002-05-02 13:15 ]</font>
Locked