Sign in to follow this  
Followers 0
aommaster

How do you use wildcards in StringCompare?

9 posts in this topic

#1 ·  Posted (edited)

Hi guys!

The title basically says it all!

I have a script which is basically is a hangman player. It guesses letters and then inputs the clue (letters and dashes) and puts it in the following form:

*****.O*.*.F******.F*O**.*O******

The dots really are spaces, but I've put them in because for some reason, Autoit tends to ignore spaces. All *'s stand for a single letter.

Now, my text file actually divides the answers in terms of number of words, so it looks something like this:

3
Hi.to.everyone

4
This.is.a.test
Welcome.to.the.solutions

This carries on all the way down to around 15 word solutions.

What my script can do is count the number of words in the string (I did this by counting the number of replacements of three spaces needed and then added 1).

So, as I see it, there are two ways to get the solution:

1.Test each and EVERY line and see if it matches the string required. I think this is quite inefficient.

2.Count the number of words, and find the line in the text file that has that number, and just read below that line.

Either way, I need it to use the *'s as wildcards that can contain any letter.

So far, all I can see that StringCompare can do is to compare two strings for an exact match, and not use wild cards at all, and I was wondering whether there was a way around that.

Please don't tell me to use arrays, because it would mean that I would need to re-write out my whole script - not fun!

edit: Just removed some typos

Thanks a lot for your time guys!

Edited by aommaster

Share this post


Link to post
Share on other sites



i think its better to use question marks as wild cards for a single letter. I don't think that asterisks have a limit for the number of letters, but im no totally sure.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hmm... I think so, I was reading about it somewhere in the manual. But that's not my point. I don't know how to use wildcards in Stringcompare...full stop :)

I'm not even sure whether stringcompare recognises wild cards...

Edit: I just checked... and no, it doesn't :P

Edited by aommaster

Share this post


Link to post
Share on other sites

I don't understand what you are going to use string compare for.

Share this post


Link to post
Share on other sites

I don't understand what you are going to use string compare for.

Well, let's say that I have a clue which contains some letters of the original solution. Filling in the spaces with wildcards, and using stringcompare to a text file that contains all possible solutions, autoit will allow me to quickly find the right answer.

Share this post


Link to post
Share on other sites

maybe you could use a stringsplit and compare one letter at a time. If the one character is a wildcard then don't run it through the stringcompare.

Share this post


Link to post
Share on other sites

maybe you could use a stringsplit and compare one letter at a time. If the one character is a wildcard then don't run it through the stringcompare.

You know what, I was actually considering doing that in a slightly different way, which was actually sticking both strings into an array. But surely there's got to be another, quicker way!

Share this post


Link to post
Share on other sites

i think that would be the quickest way actually. because it would only have to compare one character for each string. That way it wont compare characters if that string cannot possibly be the answer.

Share this post


Link to post
Share on other sites

i think that would be the quickest way actually. because it would only have to compare one character for each string. That way it wont compare characters if that string cannot possibly be the answer.

Oh dear me... I'll take a shot at it, but it's quite likely I'll be having trouble with the code :)

Oh well, it's a learning experience for me, so I really don't mind :P

Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0