TRIM command?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

TRIM command?

Mark Stuart
Hi all,

Is there a RunRev TRIM command? To remove beginning and/or trailing spaces.
If there is, I can't find it.
If there isn't, how would I script the function for this?

TIA,
Mark
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Regards,
Mark Stuart
-----------
LC 4.6.4
LC Community 6.5
WinXP/7/8
32bit and 64bit
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Brian Yennie
This script should do the trick:

repeat while (char 1 of myString = space)
     delete char 1 of myString
end repeat

repeat while (char -1 of myString = space)
     delete char -1 of myString
end repeat

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Ken Ray
In reply to this post by Mark Stuart
On 5/18/06 3:58 PM, "[hidden email]" <[hidden email]> wrote:

> Hi all,
>
> Is there a RunRev TRIM command? To remove beginning and/or trailing spaces.
> If there is, I can't find it.
> If there isn't, how would I script the function for this?

The basic trim for both sides would be (assume you don't use non-breaking
spaces) is:

  put word 1 to -1 of <string> into <var>

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: [hidden email]

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Alex Tweedly
In reply to this post by Mark Stuart
[hidden email] wrote:

>Hi all,
>
>Is there a RunRev TRIM command? To remove beginning and/or trailing spaces.
>If there is, I can't find it.
>If there isn't, how would I script the function for this?
>  
>
AFAIK, there isn't.

If this is *within* a line (or if you don't need to worry about CR for
some other reason), you can just do

    word 1 to -1 of tVar

If you need to worry about multi-line, you need to be careful (but most
TRIM functions don't, so I'm going to hope you don't either :-)


--
Alex Tweedly       http://www.tweedly.net



--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.392 / Virus Database: 268.6.0/342 - Release Date: 17/05/2006

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Sarah Reichelt-2
In reply to this post by Mark Stuart
On 5/19/06, [hidden email] <[hidden email]> wrote:
> Hi all,
>
> Is there a RunRev TRIM command? To remove beginning and/or trailing spaces.
> If there is, I can't find it.
> If there isn't, how would I script the function for this?

There was a lot of discussion about this a few months ago, so an
archive search might prove useful. However here are a couple of
suggestions to get you going:

If the extra white spaces are only at the beginning & end of the text
i.e. not between words, then this one-liner will do:

put word 1 to -1 of myText into myText

If there could be extra spaces between words, then this is what I use:

put empty into myTrimmedText
repeat for each word w in myText
  put w & space after myTrimmedText
end repeat
delete last char of myTrimmedText  -- get rid of last space

HTH,
Sarah
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

xtalkprogrammer
Hi Sarah,

If theStr contains a string with multple spaces that you want to  
replace with single spaces, try:

replacetext(theStr," +"," ")

Best,

Mark

--

Economy-x-Talk
Consultancy and Software Engineering
http://economy-x-talk.com
http://www.salery.biz

Salery is the easiest way to get your own web store on-line: http://
www.salery.biz/salery.html



Op 18-mei-2006, om 23:05 heeft Sarah Reichelt het volgende geschreven:

<snip>

>
> If there could be extra spaces between words, then this is what I use:
>
> put empty into myTrimmedText
> repeat for each word w in myText
>  put w & space after myTrimmedText
> end repeat
> delete last char of myTrimmedText  -- get rid of last space
>
> HTH,
> Sarah
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Kind regards,

Drs. Mark Schonewille

Economy-x-Talk Consultancy and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
Facebook: http://facebook.com/LiveCode.Beginner
KvK: 50277553
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Gary S.
In reply to this post by Mark Stuart
I don't claim to be a regular expression expert (just a long time  
list lurker), but I recently had the same need for a trim command and  
came up with this function:

function trimWS pText
   -- Remove all leading and trailing whitespace characters.
   -- I.E., space, tab, carriage return, line feed, form feed.

   return replaceText(pText,"(^\s+)|(\s+$)",empty)

end trimWS


Gary

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: TRIM command?

Ken Ray
On 5/19/06 4:15 PM, "Gary S." <[hidden email]> wrote:

> I don't claim to be a regular expression expert (just a long time
> list lurker), but I recently had the same need for a trim command and
> came up with this function:
>
> function trimWS pText
>    -- Remove all leading and trailing whitespace characters.
>    -- I.E., space, tab, carriage return, line feed, form feed.
>
>    return replaceText(pText,"(^\s+)|(\s+$)",empty)
>
> end trimWS

Yes, this works for everything except hard spaces (i.e. nonbreaking spaces),
which are not seen as whitespace by the regex engine.  Admittedly this
should be extremely rare that you might find one of these, but if you do, it
can ruin your day. Here's a version that takes this into account
(unfortunately it is different per platform):

function trimWS pText
   -- Remove all leading and trailing whitespace characters.
   -- I.E., space, tab, carriage return, line feed, form feed, hard space
  if the platform is "MacOS" then
    return replaceText(pWhat,"(^(\s|\xca)+)|((\s|\xca)+$)",empty)
  else
    return replaceText(pWhat,"(^(\s|\xa0)+)|((\s|\xa0)+$)",empty)
  end if
end trimWS

For those of you interested, I've been keeping track of the various forms of
trimming, and have (with RevBench's help) shown that although the above uses
less code, it is not as efficient as a much more wordy function (the
function above comes in at 0.0257 ticks).

The following trim function is so far the fastest, most comprehensive
version (0.0004 ticks):

function trim what
  if the platform is "MacOS" then put numToChar(202) into tHardSpc
  else put numToChar(160) into tHardSpc
  put (space & tab & cr & linefeed & formfeed & tHardSpc) into tWhiteSpc
  repeat
    if char 1 of what is not in tWhiteSpc then exit repeat
    else delete char 1 of what
  end repeat
  repeat
    if char -1 of what is not in tWhiteSpc then exit repeat
    else delete char -1 of what
  end repeat
  return what
end trim

However the approach provided by Jacque Gay (and others) is the simplest and
is fastest (0.0002 ticks):

function trim what
  return (word 1 to -1 of what)
end trim

but doesn't handle hard spaces and is tripped up if there is a lone double
quote in a string:

  put quote & "   this is a test   " into tString
  put trim(tString)

will *not* trim the spaces from the end of the string.

Take your pick...

:-)
   

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: [hidden email]


_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution