删除突出显示并仅在 LiveCode 中放置替换的字符串

Delete highlight and place only replaced string in LiveCode

以下用于替换特定文本并突出显示搜索和替换字符串的实时代码。搜索字符串也借助 html 代码进行搜索。现在我尝试添加新按钮来执行删除搜索字符串并仅放置替换的字符串并且不突出显示。

 on mouseUp 
 put the htmlText of field "MytextField" into myHtml 
 set the caseSensitive to true
 put the field SRText into myArrayToBe
 split myArrayToBe by CR
 put the number of lines of (the keys of myArrayToBe) into myArraylength
  repeat with i = 1 to myArraylength 
  put  myArrayToBe[i] into y
  split y by colon
  put y[1] into searchStr
  put y[2] into replaceStr
  if searchStr is empty then
  put the  0 into m
  else 
  replace searchStr with  "<strike><font bgcolor=" & quote & "yellow" & quote & ">" & searchStr & "</font></strike><font bgcolor=" & quote & "green" & quote & ">" & replaceStr & "</font>" in myHtmlend if
  end repeat 
  set the htmlText of fld "MytextField" to myHtml 
end mouseUp

我无法测试您的代码,因为我没有您的字段内容。但是要知道命令 "replace" 需要一个可以从中引用字符串的容器:

用 fld 1 中的 replaceString 替换 searchString

不会报错,但在以下情况下不需要使用"the":

将 0 放入 m(只说“将 0 放入 m)

将字段 SRText 放入 MyArrayToBe(将字段 SRText 放入...) 你明白了。

无论如何,写回一些我们可能会评估的测试文本,或者更好的是,用简单的文本自己测试。然后当它起作用时,在你的真实文本上试试。

克雷格·纽曼