INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Help with string match?

Help with string match?

(OP)
Folks,
I am at a loss... Im trying to use 'string match' to compare 2 items in a list. However, the 2 items contain special characters. This all falls into a much larger script that I wrote but I wrote a small one here to show what I am doing as an example.

#!/usr/local/bin/expect

set MasterList [list]
lappend MasterList {\"B\"}
lappend MasterList {\"B\"}

puts "MasterList=$MasterList"

set value [lindex $MasterList 0]
set value1 [lindex $MasterList 1]
if {[string match $value $value1] != 1} {
puts "They do not match"
} else {
puts "They match"
}

I'm just stuffing 2 strings(with special chars) into the list. Then pulling them out individually and comparing them. The 'string match' comparison is always returning a 0, saying they dont match....
Any ideas as to how to compare strings with special chars like this?
Thanks in advance for your help!

RE: Help with string match?

Hi

Why you want to compare them with string match ?

Anyway. Backslashes ( \ ) have special meaning in the pattern but not in the string. So backslashes in the pattern must be escaped with backslashes :

CODE --> )

string match {"B"} {\"B\"}

Feherke.
http://feherke.github.com/

RE: Help with string match?

(OP)
Feherke,
Thanks for replying... As I had mentioned, this is all part of a much bigger script. This other script reads in strings and shoves them into lists. These lists are then compared.... In these lists, i have alot of these special chars like \.... I need a way to compare these 2 strings in this manner. I dont particularly need to use string match.

RE: Help with string match?

Hi

Oops. Something gone wrong while posting. Intended to write :

CODE --> )

string match {\\"B\\"} {\"B\"}

Quote (alord)

I dont particularly need to use string match.
Ok. Then I suggest to use string equal :

CODE --> )

if {[string equal $value $value1] != 1} {

Feherke.
http://feherke.github.com/

RE: Help with string match?

(OP)
Feherke,
That was what I needed!!!! Thanks for your help! It's working now!
Alan

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close