Find/Replace woes

Adrian Williams adrian at clubtype.co.uk
Sat Nov 18 09:51:40 EST 2006


Hi Eric,
Thanks for your suggestion but...

This code produces "Could not find string".
All buttons and field are on same card.
There is text in both edtFind and edtReplace fields.
So why is tFindStr not in tText ???
Adrian

On 18 Nov 2006, at 09:28, Eric Chatonet wrote:

> Hi Adrian,
>
> May be you could use replaceText:
>
> on mouseUp
>   local tFindStr,tRepStr,tText,tHtml,tCanReplace
>   -----
>   put fld "edtFind" into tFindStr
>   put fld "edtReplace" into tRepStr
>   put fld "edtText" into tText
>   put the htmlText of fld "edtText" into tHtml
>   -----
>   put CanReplace(tFindStr,tRepStr,tText) into tCanReplace --
>   if tCanReplace then
>     set the htmlText of fld "edtText" to 
> replaceText(tHtml,tFindStr,tRepStr)
>   else answer tCanReplace
> end mouseUp
> ---------------------------------
> function CanReplace tFindStr,tRepStr,tText
>   if tFindStr = empty then return "Find string is empty."
>   if tRepStr = empty then return "Replace string is empty."
>   if tText = empty then return "Text is empty."
>   if tFindStr is not in tText then return "Could not find find string."
>   return true
> end CanReplace
>
> Best Regards from Paris,
> Eric Chatonet
>
> Le 18 nov. 06 à 09:46, Adrian Williams a écrit :
>
>> Herschel,
>> This works fine if the only word in the "edtText" field matches the 
>> "edtReplace" field.
>> But if there are ANY other words at all in "edtText", nothing gets 
>> replaced.
>> So how can Replace be made to actually replace all instances?
>> Should this be Replace Text rather than Replace field?
>> Thanks,
>> Adrian
>>
>> On 16 Nov 2006, at 21:24, Hershel Fisch wrote:
>>> On 11/16/06 12:22 PM, "Adrian Williams" <adrian at clubtype.co.uk> 
>>> wrote:
>>>>
>>>> SCRIPT: FIND BUTTON
>>>> on mouseUp
>>>>  --set text of field "edtReplace" to ""
>>> Put "" into fld "edtReplace"
>>>>  --put text of field "edtFind" into tFindText
>>>> -- find string tFindText in field "edtText"
>>> Find fld "edtFind" in fld "edtText"
>>>> end mouseUp
>>>>
>>>> SCRIPT: REPLACE BUTTON
>>>> on mouseUp
>>>>  --get the htmlText of field "edtText"
>>>
>>>>  --replace text of field "edtFind" with text of field "edtReplace" 
>>>> in it
>>> Replace fld "edtFind" with fld "edtReplace" in fld edtText"
>>>>  --set the htmlText of field "edtText" to it
>>>> end mouseUp
>>>
>>> Whell this is my version ? Hershel
>>>>
>>>> Thanks,
>>>> Adrian
>>>> ______________________
>>>> Club Type
>>>> http://www.clubtype.co.uk
>>>> adrian at clubtype.co.uk




More information about the use-livecode mailing list