Hi Hugh

Usual technique to seek extra time from a client is to ask more questions. :-)

I assume the string has to match on the start of a word boundary.

e.g.

put "This is a  test." into sourceText (note the punctuation)
whole("is is a  test",sourceText)  => FALSE

Case-sensitivity?

Dave


On 13 Jun 2007, at 20:35, [EMAIL PROTECTED] wrote:

The Challenge:
"Write a function that returns TRUE or FALSE for the existence of any valid text string existing within any longer text string. (To make things easier we limit this to ASCII text; right-to-left double-bite Unicode character reco
gnition can come later :-)"

e.g.
put "This is a  test-piece." into sourceText (note the punctuation)
whole("This is a  test",sourceText)   => FALSE
whole("This is a  test-piece",sourceText)  => TRUE



1. Philip's "creative thinking" entry (that unfortunately only handles
tail-end period  punctuation):

put "This is a test." into myLine
replace " " with "*" in  myLine
put fld 1 into myField
replace ". " with ".#" in myField (note : period + space. use two spaces
if needed)
replace space  with "*" in myField
replace "#" with space in myField
if myLine  is among the words of myField then return true



2. Dave's "almost  there" entry....

This doesn't check that the matched target starts on a word boundary,
But a simple check on char (tOff -1) or  whether tOff is at the
beginning of the target shoud do it.

function whole  s,t
  put length(s) into tNumChars
  put  ",.;:?!" & space & tab & cr & numToChar(13) into  tWB
  put offset(s,t) into tOff
  if tOff =  0 then return false
return length(t) = (tOff + tNumChars - 1) OR char (tOff + tNumChars) of
t is in tWB
end  whole


3. Ken's "sneaky" entry that relies on a field as the source (probably because I did not spec out the problem properly, meant stringSource rather than
field, and he's too damn good at reading things  carefully):

put wholeWordMatch("This is a test",long id of fld  1)

function wholeWordMatch  pFindText,pFldRef
    find whole pFindText in  pFldRef
    put the result into  tResult
    find  empty
    return (tResult <> "not  found")
end wholeWordMatch



Anyone care to top these? The winner will be placed in the stdLib assuming
common consent!

/H




_______________________________________________
metacard mailing list
metacard@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/metacard

_______________________________________________
metacard mailing list
metacard@lists.runrev.com
http://lists.runrev.com/mailman/listinfo/metacard

Reply via email to