scripting challenge Contest ?

FlexibleLearning at aol.com FlexibleLearning at aol.com
Fri Jul 6 13:35:14 EDT 2007


Hi Brian

For a "simple approach" solution, this is pretty darn  close, except where 
trailing punctuation forms part of the string to  find...

put "This is a great script - Brian did good!" into  sourceText
put "script - Brian" into findThis
put wholeFindIt (sourceTest,  findThis) => FALSE  # should be TRUE

It's more tricky than may at  first appear, this one!

/H

---- Original message ----

I actually saw this thread on the Metacard list, but didn't have  a  
moment to really think about it. I'm not sure I understand  completely  
the "must handle all punctuation" part, but regardless it  might get  
the ball rolling for me to post a simple approach and you  can tell me  
the flaws =). This is only lightly tested, but maybe it's  close? This  
basically tries to strip and normalize all punctuation  first, and  
then search for a whole match.

function wholeFindIt  sourceText, findThis
## remove punctuation  from both source and chunk to find
## commas,  colons, semicolons exclamations, periods, questions, new  lines

repeat for each char c in  (";:.,!?"&return)
replace c with space in  sourceText
replace c with  space in findThis
end  repeat

## replace hyphens followed by  spaces
## "I like you- are you single?" =>  "I like you are you single"
## "I like  super-fast ultra-cars!" => unchanged

replace ("-"&space) with space in  sourceText
replace ("-"&space) with space  in findThis

## normalize multiple spaces  down to one

repeat while  (offset(space&space, sourceText) >  0)
replace  (space&space) with space in sourceText
end  repeat

repeat while  (offset(space&space, findThis) >  0)
replace  (space&space) with space in findThis
end  repeat

## pad everything with spaces to  get whole word matches

if (char 1 of  sourceText is not space) then put space before  sourceText
if (char -1 of sourceText is not  space) then put space after sourceText

if  (char 1 of findThis is not space) then put space before  findThis
if (char -1 of findThis is not space)  then put space after findThis

##  search!
return (offset(findThis, sourceText)  > 0)

end wholeFindIt
 
---- end original message ----



   



More information about the use-livecode mailing list