Jump to content
Macro Express Forums

Search For Specific Text


Wulfgar

Recommended Posts

All,

 

I must copy a block of text. I have to search that text for a tax id number. Tax id numbers are always 9 digits. My organization uses no punctuation, so they will always be in the form nnnnnnnnn.

 

It's easy to detect if a particular taxid is in the text. I'm having a hard time finding any random taxid, and then extracting it. That's what I need.

 

1. Does the block contain a taxid?

2. If so, copy it into a variable.

 

I'm fairly proficient with MEX, but this one has me stumped.

 

Any thoughts?

Link to comment
Share on other sites

Macro Express does not have Regular Expressions built in, so you could instead chop away at the text line until you either find, or do not find a 9-digit integer.

Variable Set String %T1% "AaBbCc 987654321"
Repeat Until %N1% <> %N1%
 Variable Modify String: Convert %T1% to integer %N1%
 If Variable %T1% = ""
   OR
 If Variable %N1% >= 100000000
   Repeat Exit
 End If
 Variable Modify String: Delete Part of %T1%
Repeat End

<TVAR2:01:01:AaBbCc 987654321><REP3:08:000002:000002:0001:1:01:N1><TMVAR2:05:01:01:000:000:><IFVAR2:1:01:1:><OR><IFVAR2:2:01:5:100000000><EXITREP><ENDIF><TMVAR2:11:01:00:001:001:><ENDREP>

Link to comment
Share on other sites

Hi,

Here's another option?

Put 'block of text" in T2;

Search for any digit

If found, check if the next 9 digits make a number

Display it (or change this to save it somewhere?)

Keep checking till end of block of text

// Set a string containing any digit

Variable Set String %T1% "0987654321"

// Set a string T2 containing block of text

Variable Set String %T2% "987654321 abcdefh rt rth t rth rthrth rwth rtth rwth rth rtht rt 999999999wtryh wy try rty rwy rtj rwthwrhwrh rwth rwth rwth rt hr"

Variable Set Integer %N2% from Length of Variable %T2%

Variable Set Integer %N1% to 0

// Search for any digit

Repeat Until %N1% = %N2%

  Variable Modify Integer: Inc (%N1%)

  Variable Modify String: Copy Part of %T2% to %T3%

  If Variable %T1% contains variable %T3%

    // Check if it is the first of 9

    Variable Modify String: Copy Part of %T2% to %T4%

    Variable Modify String: Convert %T4% to integer %N3%

    If Variable %N3% >= 100000000

      Text Box Display: found one, N3= %N3%, at

      Variable Modify Integer: %N1% = %N1% + 9

    End If

  End If

Repeat End

<REM2:Set a string containing any digit><TVAR2:01:01:0987654321><REM2:Set a string T2 containing block of text><TVAR2:02:01:987654321 abcdefh rt rth t rth rthrth rwth rtth rwth rth rtht rt 999999999wtryh wy try rty rwy rtj rwthwrhwrh rwth rwth rwth rt hr><IVAR2:02:12:2><IVAR2:01:01:0><REM2:Search for any digit><REP3:08:000001:000002:0001:1:01:N2><NMVAR:08:01:0:0000001:0:0000000><TMVAR2:10:03:02:N01:001:><IFVAR2:4:01:7:T3T><REM2:Check if it is the first of 9><TMVAR2:10:04:02:N01:009:><TMVAR2:05:04:03:000:000:><IFVAR2:2:03:5:100000000><TBOX4:T:1:CenterCenter000278000200:000:found one, N3= %N3%, atN1=%N1%><NMVAR:01:01:1:0000001:2:0000009><ENDIF><ENDIF><ENDREP>

Randall

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