Jump to content
Macro Express Forums

can I test what a variable contains using wildcards?


margaret
 Share

Recommended Posts

I would like to be able to test whether a variable contains any three characters where the first and last character are any lowercase letters and the middle character is a space. I can do it with specific characters, but is there a way to use wildcards so I could test for all such situations?

Link to comment
Share on other sites

Try this:

- Extract each of the 3 characters into 3 string variables, say v1, v2 and v3

  If v1 >= a (don't ignore case)
 AND
 If v1 <= z (don't ignore case)
 AND
  If v2 = " "
 AND
 If v3 >= a (don't ignore case)
 AND
 If v3 <= z (don't ignore case)
  It's what I want

Does that do it (I'll leave you to write the code)?

Link to comment
Share on other sites

Try this:

- Extract each of the 3 characters into 3 string variables, say v1, v2 and v3

  If v1 >= a (don't ignore case)
 AND
 If v1 <= z (don't ignore case)
 AND
  If v2 = " "
 AND
 If v3 >= a (don't ignore case)
 AND
 If v3 <= z (don't ignore case)
  It's what I want

Does that do it (I'll leave you to write the code)?

 

Hi Paul,

 

Thanks. I think that would do it if I already knew where the three characters are in the string, but I will not know that. I want to find any two lowercase characters that are separated by a space (i.e., every word after a space should begin with a capital letter, but sometimes there are unwanted spaces in the middle of a word, hence before a lowercase character). To use the above, I guess I would have to loop through the variable finding all the spaces and then testing the surrounding characters for case. I will work on that.

 

What I was hoping for was some way to look for the combination as a search parameter, like "if <string> contains <[a-z] [a-z]> then...

 

By the way, when writing a forum message, every time I try to type an apostrophe, my cursor focus gets moved out of the message and into a "Find" box. Is this to be expected?

Link to comment
Share on other sites

Thanks. I think that would do it if I already knew where the three characters are in the string, but I will not know that. I want to find any two lowercase characters that are separated by a space (i.e., every word after a space should begin with a capital letter, but sometimes there are unwanted spaces in the middle of a word, hence before a lowercase character). To use the above, I guess I would have to loop through the variable finding all the spaces and then testing the surrounding characters for case. I will work on that.

No, don't do that! Simply replace all multiple spaces with single spaces, as in Change " " to " " (all occurrences). hen my code will work.

By the way, when writing a forum message, every time I try to type an apostrophe, my cursor focus gets moved out of the message and into a "Find" box. Is this to be expected?

Ah, the dreaded Firefox problem, which occurs randomly throughout Firefox.

There's 2 ways to solve this:

- Clear your cache

Tools / Options / Privacy / Clear Now / Cache

This should solve the problem until it next occurs

 

- Refer to the last paragraph in this URL and install the recommended extension

SearchHotkeys

 

There are other recommendations out there, but they have never worked for me.

Link to comment
Share on other sites

No, don't do that! Simply replace all multiple spaces with single spaces, as in Change " " to " " (all occurrences). Then my code will work.

 

It's not a question of multiple spaces. It's spaces where a space should not be, in the middle of a word. For example, suppose you had a name like "John P. Pas solo." There shouldn't be a space between the two s's. So if I have the macro check the first space (doesn't fit parameters, thecharacter following the space is uppercase), then the second space (doesn't fit parameters, the character following the space is a period), then when it comes to the third space, it will fit the parameters (surrounded by lowercase letters) so the macro will now "know" that this space shouldn't be there.

 

Aha, so the other problem is Firefox. Thanks, I'll look into that.

Link to comment
Share on other sites

It's not a question of multiple spaces. It's spaces where a space should not be, in the middle of a word.

Ah, it becomes clearer!

You could always try a different approach:

- Change all non lower-case letters to, say, "@" (excluding spaces)

You can do this with a Repeat loop, using a variable containing all the non lower-case characters and extracting each character

 

- Replace all occurrences of "@ " with "@@"

 

- Replace all occurrences of " @" with "@@"

 

Now (I think <g>) any remaining spaces are the ones you were looking for

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...