突出显示字符前后——

Highlight Before and after the characters --

我想突出显示“--”前后的字符串。例子好 - 坏在这里我想强调好的和坏的。每当 -- 出现时,在字符串成为高亮之前和之后。可能吗。

假设您在字段 "mytext" 中有以下文本:

This text comes before -- this text comes after.

LiveCode(与大多数应用程序一样)不允许不连续的选择,因此 'select' 命令仅适用于连续运行的文本。

select word 1 to 3 of fld "mytext"

但是您可以通过设置单独文本运行的背景颜色 属性 来模拟选择突出显示:

put wordOffset("--",fld "mytext") into tWordIndex
set the backgroundColor of word 1 to tWordIndex - 1 of fld "mytext" to the hiliteColor
set the backgroundColor of word tWordIndex + 1 to -1 of fld "mytext" to the hiliteColor

当然,您可以在两个 'set' 语句中使用任何有效的文本块表达式,具体取决于您想要 "highlight"“--”前后的文本部分。

要清除字段中的背景颜色,请执行以下操作:

set the backgroundColor of char 1 to -1 of fld "mytext" to empty