lemming Posted July 23, 2010 Report Share Posted July 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
paul Posted July 23, 2010 Report Share Posted July 23, 2010 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 Quote Link to comment Share on other sites More sharing options...
lemming Posted July 24, 2010 Author Report Share Posted July 24, 2010 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.