Stripping trailing spaces from a string
Ken Ray
kray at sonsothunder.com
Sun Mar 5 01:33:44 EST 2006
On 3/4/06 10:00 PM, "Jim Witte" <jswitte at bloomington.in.us> wrote:
> How can I use a RegEx to strip trailing white-space? I tried:
>
> get matchText(theExpr, "(.*)\s*", theExpr)
>
> where theExpr is "0025E95C mov r5, r0 "
Here's a version I have that trims whitespace from both sides of a string,
and includes 'normal' whitespace, along with hard spaces (watch word wraps):
function trim pWhat
local dummy,tRetVal
if the platform is "MacOS" then put "\xca" into tHardSpc
else put "\xa0" into tHardSpc
get matchText(pWhat, "(?s)^(\s|" & tHardSpc & ")*(.*?)(\s|" & tHardSpc &
")*$",dummy,tRetVal)
return tRetVal
end trim
However using RegEx for trimming is not the fastest approach, although the
difference between 0.0391 ticks for the RegEx version vs. 0.0004 ticks for
the fastest version is not recognizable unless you have to do it thousands
of times...
Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
More information about the use-livecode
mailing list