put word 1 to -1 of tString into tString -- staggeringly simple

Ken Ray kray at sonsothunder.com
Sat Aug 13 19:57:02 EDT 2005


On 8/13/05 3:22 PM, "Sivakatirswami" <katir at hindu.org> wrote:

> What is the ASCII for a hard space and while the space might be
> retained, I do believe even with a  a hard space, the empty line(s)
> deletion at beginning and end of the entire text chunk would still be
> achieved (the original goal)
> 
> right?

The ASCII value for a hard space is 202, and unfortunately the answer
depends on what you've got in your container. If you have:

(CR)
(spc)(CR)
Test1(CR)
Test2(CR)
(CR)
(spc)(CR)

when you do word 1 to -1 you get:

Test1(CR)
Test2

However, if the container is:

(CR)
(hardspc)(CR)
Test1(CR)
Test2(CR)
(CR)
(hardspc)(CR)

when you do word 1 to -1 you get:

(hardspc)CR
Test1(CR)
Test2(CR)
(hardspc)

This is why I use the regex expression for my "stsTrim" function instead of
"word 1 to -1"... it's not as elegant, but it *does* handle all the
situations.

function stsTrim pWhat
  local tRetVal
  get matchText(pWhat, "(?s)^\s*(.*?)\s*$", tRetVal)
  return tRetVal
end stsTrim

But if you know for sure that you won't be dealing with hard spaces, "word 1
to -1" is really elegant and easier to use I'd think.


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