Find/Replace woes

Eric Chatonet eric.chatonet at
Sat Nov 18 10:32:57 EST 2006

Hi Adrian,

tText is the text of the field where you want to search/replace, right?
If the search string is not in the text of this "main" field, the  
function will return "Could not find string".

Some comments about the CanReplace function:
Each condition line is evaluated as one goes along: if true the  
specified value is returned and if false the next line is evaluated.
This way of scripting is efficient and easy: instead of having  
multiple conditions, you have only simple lines.

Sounds like your search string is not in your main text :-)
Another clue: be sure to insert handlers to trap returnInField in  
your "edtFind" and "edtReplace" fields or you may have additional  
carriage returns in them.
Just insert these "dead" handlers in the scripts of your fields:

on returnInField
end returnInField

Hope this helps.

Le 18 nov. 06 à 15:51, Adrian Williams a écrit :

> 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>  
>>>> wrote:
>>>>> 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
>>>>> 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

Best Regards from Paris,
Eric Chatonet
----------------------    eric.chatonet at

More information about the Use-livecode mailing list