string match fails for strings containing "[" 
Author Message
 string match fails for strings containing "["

Quote:

> Tcl 8.2.1 Bug:  Generated by Scriptics' bug entry form at
> Submitted by:  Jim Russell
> Synopsis:  string match fails for strings containing "["

> ReproducibleScript:
> From tclsh8.2 command line I typed:

> set a {i[0]}
> set b $a
> string match $a $b

> ObservedBehavior:
> Setting b to the value of a should result in a successful match when comparing a to b.

This is erroneous, because the [] are special characters in glob
matching, so you are really asking:
        string match i0 {i[0]}

If you want to avoid mistakes like this, use [string equal].

--
   Jeffrey Hobbs                          The Tcl Guy
   jeffrey.hobbs at scriptics.com         Scriptics Corp.



Sat, 27 Apr 2002 03:00:00 GMT  
 string match fails for strings containing "["

Tcl 8.2.1 Bug:  Generated by Scriptics' bug entry form at
        http://www.scriptics.com/support/bugForm.html
Responses to this post are encouraged.
------

Submitted by:  Jim Russell
OperatingSystem:  sunos
Machine:  x86 solaris, AMD microprocessor
CustomShell:  No.
Synopsis:  string match fails for strings containing "["

ReproducibleScript:
From tclsh8.2 command line I typed:

set a {i[0]}
set b $a
string match $a $b

ObservedBehavior:
Setting b to the value of a should result in a successful match when comparing a to b.

DesiredBehavior:
I would expect the string match to return "1".



Sun, 28 Apr 2002 03:00:00 GMT  
 string match fails for strings containing "["

Quote:

> Tcl 8.2.1 Bug:  Generated by Scriptics' bug entry form at
>         http://www.scriptics.com/support/bugForm.html
> Responses to this post are encouraged.
> ------

> Submitted by:  Jim Russell
> OperatingSystem:  sunos
> Machine:  x86 solaris, AMD microprocessor
> CustomShell:  No.
> Synopsis:  string match fails for strings containing "["

> ReproducibleScript:
> From tclsh8.2 command line I typed:

> set a {i[0]}
> set b $a
> string match $a $b

> ObservedBehavior:
> Setting b to the value of a should result in a successful match when comparing a to b.

> DesiredBehavior:
> I would expect the string match to return "1".

Read the manual, [string match] takes a glob style pattern and a string,
not two plain strings. [] have special meaning in glob style patterns.
If you want to compare two strings use [string compare] or [string equal]
if available.


Sun, 28 Apr 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. string matching "~"

2. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

3. Matching strings that contain braces

4. scanf("%s", string) or scanf("%s", &string)? Both work, yet...

5. Matching string that is not between "<a " and "</a>"

6. Problem with string module and strings containing \0

7. Can I use "expect -re " to match string and get sub-string ?

8. "Overflow " string in report

9. String "length"

10. pointer-delimited strings, "$egments", in H3sm 1.4

11. Help:How to execute "strings"?

12. scan string for "returns"

 

 
Powered by phpBB® Forum Software