Jump to content
Macro Express Forums

Checking for letters, numbers in string-variables


Recommended Posts

Hi everybody,

 

i wonder how to distinguish between string and integer variables. I need an Logic-If command which can do that. If letters are included in a stringvariable the macro should do something else then if the stringvariable consist of or contains numbers.

 

Thanks for helping

Alexandra

Link to comment
Share on other sites

There are a couple of approaches I use.

  1. If you just want to test if a string of text is an integer convert it to integer and then back to a temp text var and compare. If the test is the same as the original then it’s an integer.
  2. To test if there’s a numeral in the text I create a numeral test variable “1234567890”, get the length of string tested, repeat length number of times incrementing a counter, copy one character from text at position counter, If numeral test var contains character then set a Boolean var to indicate I found it and break. Then after the loop if the found Boolean is true then do whatever else...
  3. Inverse of the one above. That is repeat 10 time and do the “If contains” against the string your testing.
  4. Repeat as above but instead get the ASCII value and if greater than 47 and led than 58 then it’s a numeral. This is often more useful detecting larger sets like upper/lower case letters.

I’m sure there are other ways but those are a few I use time to time.

Link to comment
Share on other sites

Interesting!

 

Now as i see it it looks quite obvious, but i´m sure it would have taken me some time to figure that out. I was searching for the appropriate command. For me actually approach 1 is enough.

 

I´m glad they implemented that Split String-command a while ago. Maybe some more variable-commands would help avoiding those clever workarounds. :unsure:

 

Thank You

Alexandra

Link to comment
Share on other sites

I´m glad they implemented that Split String-command a while ago. Maybe some more variable-commands would help avoiding those clever workarounds. :unsure:

I've requested a few array commands like sort in the past and you inspired me to request a few more but if you have any ideas of useful commands you should request them.

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...
×
×
  • Create New...