How trim?

Mark Greenberg markgreenberg at cox.net
Sun Oct 23 09:47:50 EDT 2005


Ah, I never get to provide a solution to these questions... until  
now.  Usually they are beyond my hobbyist skills or a dozen heavy  
hitters have solved the dilemma already by the time I read the  
digests.  Now the trick is posting this before anyone else beats me  
to it.  ; )

Bob, many types of characters are invisible.  Collectively called  
"white space," they include TAB, hard space, space, new line, form  
feed, etc.  If I'm not mistaken, the list gets even longer if the  
data is in unicode.  Regular Expressions has a way to catch all of  
these at once.  In Rev this looks like this:

-- to trim leading white space
ReplaceText("    The cat crawled under the mat.        ","^\s+","")
-- \s means any white space, and + means one or more of them.

-- likewise, to trim trailing white space
ReplaceText("    The cat crawled under the mat.         ","\s+$","")

The 1 to -1 solution is best for stripping both ends.

         Mark Greenberg

PS  Thanks for the 15 seconds of fame.





More information about the use-livecode mailing list