Repeat until (0r "while") not working

Ken Ray kray at sonsothunder.com
Wed Aug 10 15:27:53 EDT 2005


On 8/10/05 6:58 AM, "Jon" <jbondy at sover.net> wrote:

> Ken and Chipp are  being very helpful when they provide useful/working code,
> but I'm more curious about why the original code did not work.  It looked
> reasonable to me: the kind of code I might actually use some day, and get
> stuck on.
> 
> Any thoughts?

Thanks for posting this, Jon... it will help others as well. Here's the
stuff I found when I put (CR & CR & "This is a test" & CR & CR) into a field
and then ran the original code:

> put fld "transcript" into tFinalTranscript
> 
> # clean up extra lines at beginning and end
> 
> repeat while ((line 1 of tFinalTranscript) is empty)
>    delete line 1 of tFinalTranscript
> end repeat
> 
> repeat until ((the last line of tFinalTranscript) is not empty)
>    delete the last line of  tFinalTranscript
> end repeat
> 
> put tFinalTranscript
> exit to top


- It removed all the CRs from the beginning of the string
- I removed the only one of the CRs from the end of the string

Leaving me with:  "This is a test" & CR

As to why the original test seemed to leave what appeared to be CRs at the
beginning made me think that some other whitespace (space, tab, etc.) was on
the line which is why it couldn't be deleted.

As to why there were CRs left at the *end*, seemed to prove out in my test.
The reason is that when you delete the last line, that doesn't remove the
preceding CR which is at the end of the previous line. So you'll always end
up with a trailing CR (as I did).

This is why I proposed my Trim function, since it handles all these things.
However the original code would work, so long as:

1) You can be guaranteed that the leading/trailing whitespace is only CRs,
and

2) That you add the following line just before you do the "put":

if char -1 of tFinalTranscript = CR then delete char -1 of tFinalTranscript

HTH,

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