Jump to content
Macro Express Forums

Count Strings within in a String Variable


Recommended Posts

One of my scripts copies information to the clipboard, then copies the clipboard to a text variable for further processing. After several manipulations, I need to know the number of commas in the text variable.

 

Is there a straightforward way to do this in MEP?

 

I found a solution, but there must be a simpler way! See below. My approach involves 45 or 50 lines of code that incrementally replace every character, except commas, with nothing. I am left with a text variable that consists only of commas, so I get the answer by asking for the length of the string variable:

 

Variable Modify String: Replace "a" in %Text% with ""

Variable Modify String: Replace "b" in %Text% with ""

Variable Modify String: Replace "c" in %Text% with ""

etc.

 

Variable Modify String: Replace "1" in %Text% with ""

Variable Modify String: Replace "2" in %Text% with ""

Variable Modify String: Replace "3" in %Text% with ""
etc.

 

Variable Modify String: Replace "-" in %Text% with ""

Variable Modify String: Replace "." in %Text% with ""

Variable Modify String: Replace "(" in %Text% with ""

etc.

 

Variable Set Integer %NumberOfCommas% to the length of variable %Text%

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...