2015-04-30 90 views
0

我想在第一次出现时替换字符串。在使用下面的代码时,它很好地代替了所有的匹配情况。我如何更改我的代码?谁能帮忙?如何在首次出现时替换字符串

on mouseUp 
    replace "Malayalam" with "English" in field "text" 
end mouseUp 

回答

0

使用wordOffset功能:

on mouseUp 
    set the wholeMatches to true -- OPTIONAL 
    put wordOffset("Malayalam",field "text") into N 
    if N <> 0 then put "English" into word N of field "text" 
end mouseUp 

可选行将会导致更换只出现在源字的精确匹配。例如,“马拉雅拉姆”将被取代,但“马拉雅拉姆”不会。

有些情况下,wholeMatches必须使用,例如,以取代“是”,在下面的句子:

这是一些文本。

如果wholeMatches未启用,则LiveCode将查找单词“This”中第一个出现的“is”。

+0

谢谢Scott Rossi伟大的编码 –

+0

Scott,将wholeMatches设置为true仍然会导致wordOffset匹配您示例中的“malayalam”。 “马拉雅拉姆语”和“马拉雅拉姆语”之间的区别将通过将caseSensitive属性设置为true而非wholeMatches属性来捕获。 – Devin

+0

德文,编辑了一个更正的例子。 –

相关问题