scripting challenge Contest ?

FlexibleLearning at aol.com FlexibleLearning at aol.com
Sat Jul 7 00:58:23 EDT 2007


 
 
Well done, Sakari! This is impressive and building on prior published  work 
is always sound practice. We may be close to an optimizable script here,  folks.
 
Your script handles the criteria including case sensitivity, except for  ends 
of line (CR, LF and CRLF) and tab...
 
put "This is a Great Script - a fast  test-Piece."&CRLF&TAB&"Well done!" into 
sourceText
put "test-Piece."&CRLF&TAB&"Well" into  stringToFind
answer whole (stringToFind,sourceText) =>  TRUE

Tha challenge is still on!
 


/H



I probably suck on this since I'm a noob, but the nevertheless I had fun  
with this one.. :D This is not optimized so it might have some overhead.  
I also nicked a piece of code from brian's one and changed it to my  
needs, hopefully you can forgive me ;)

button script:

on  mouseUp
put "This is a  test-piece." into sourceText
put whole("a test",sourceText) & return after tString
put  whole("is a test-piece",sourceText) & return after tString
put  whole("is a test-piece.",sourceText) & return after tString
put  "This is a great script - Brian did good!" into sourceText
put  whole("script - Brian",sourceText) & return after tString
answer  tString
end mouseUp


function whole stringToFind,  sourceText
set the caseSensitive to true
set the  wholematches to TRUE
put zero into tSkip
repeat while  wordOffset(word 1 of stringToFind, sourceText, tSkip) > 0
add wordOffset(word 1 of stringToFind, sourceText, tSkip) to tSkip
put FALSE into tReturn
repeat with x=2 to the number of  words in stringToFind
get matchText(word x of  stringToFind, "^" & word (tSkip-1+x) of sourceText & 
"$" )
if it is FALSE then
put  stripPunctuation(word (tSkip-1+x) of sourceText) into strippedString
get matchText(word x of stringToFind, "^" &  strippedString & "$")
if it is not TRUE  then
put FALSE into tReturn
exit repeat
else
put TRUE into tReturn
end if
else
put TRUE into tReturn
end if
end  repeat
if tReturn is TRUE then
return  TRUE
exit whole
end if
end  repeat
return FALSE
end whole


function stripPunctuation  tString
repeat for each char c in (";:.,!?"&return)
replace c with empty in tString
end  repeat
return tString
end  stripPunctuation


FlexibleLearning at aol.com wrote:
> There is a  wee challenge I posted to the metacard list for a function that 
>  returns whether a whole text string is in a variable (must handle all  
> punctuation and ends of line etc), along the lines  of...
>
> put "This is a test-piece." into sourceText (note  the  punctuation and 
hyphen)
> whole("a  test",sourceText)   =>  FALSE
> whole("is a  test-piece",sourceText)  => TRUE
> whole("is a  test-piece.",sourceText)  => TRUE
>
> There have been some  good  attempts but it has yet to be solved 
completely. 
> Perhaps  someone on this list is up for it.
>  
>  /H

>
>
> Fri Jun 29 Jacqueline Landman Gay  wrote:
>
>> I  do miss those scripting challenges though. I wish  this list
>>  would indulge more, it was great fun. The last one I can recall  on
>> this list was the creation of a working clock face. By the   time 
>> everyone
>> was done we had a very efficient and  effective script, and I think
>> everyone who followed the  exchange learned a lot.




   



More information about the Use-livecode mailing list