Jump to content
Macro Express Forums

Compress spaces demo


lemming
 Share

Recommended Posts

This short script demonstates how to remove extra spaces from data, for example:

 

Before:
14770512        7       0       9       1  
this   is   too  gappy?
testing    testing   1       0       5       0

After:
14770512 7 0 9 1 
this is too gappy?
testing testing 1 0 5 0

 

The script makes use of the "Set Variable to Position of Text" command, which is essentially a search command. The script repeatedly searches for 2 consecutive spaces and replaces them with 1 space.

Compress spaces demo.mex

Link to comment
Share on other sites

An alternative (better?) method might be:

set string t10 to your gappy string
repeat until n1 <> n1 -- endless loop
 set integer n1 to the length of variable t10
 variable modify string: replace "  " in t10 with " " --replace all instances
 set integer n2 to the length of variable t10
 if n2 = n1 repeat exit --because nothing changed, we're done
end repeat

Link to comment
Share on other sites

Hi Paul, that's an interesting use for "set to the length of variable". I'll have to remember that one.

 

It's good to have alternative approaches to the problem!

 

An alternative (better?) method might be:

set string t10 to your gappy string
repeat until n1 <> n1 -- endless loop
 set integer n1 to the length of variable t10
 variable modify string: replace "  " in t10 with " " --replace all instances
 set integer n2 to the length of variable t10
 if n2 = n1 repeat exit --because nothing changed, we're done
end repeat

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