【问题标题】:Highlight Before and after the characters --突出显示字符前后——
【发布时间】:2015-04-09 04:46:28
【问题描述】:

我想突出显示“--”之前和之后的字符串。好的例子——坏的在这里我想强调好的和坏的。每当 -- 出现时,字符串之前和之后就会成为突出显示。是否可以。

【问题讨论】:

    标签: livecode livecoding


    【解决方案1】:

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

    This text comes before -- this text comes after.
    

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

    select word 1 to 3 of fld "mytext"
    

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

    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”语句中使用任何有效的文本块表达式,具体取决于您要“突出显示”“--”之前和之后的文本部分。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 1970-01-01
      • 2016-03-26
      • 2014-06-15
      • 2022-01-01
      • 1970-01-01
      相关资源
      最近更新 更多