问题描述
我能够成功使用substitute函数搜索整个字符串列并查找“ hello”并将其替换为“ world”。
我使用了Calculation field指令来创建一个新的计算字段,该字段运行以下代码:
Substitute(column3;“hello”;“world”)
所以现在我有一个新的column4,它是column3的精确副本,只是“ hello”被替换为“ world”。
但是我还想做更多替换,例如:
Substitute(column3;“BBB”;“Better Business Bureau”)
Substitute(column3;“CCC”;“Cats Candy Cinder”)
这将创建一条错误消息,指示我需要在替换语句之间放置+,-,*运算符。我实际上不是在这里进行数学计算,只是进行一些字符串操作。
如何在File Maker Pro中实现一个脚本,该脚本按顺序执行所有3种替换操作?
解决方法
您可以这样做:
Substitute(column3;[“AAA”;“Acme”] ; [“BBB”;“Better Business Bureau”] ; [“CCC”;“Cats Candy Cinder”])
此堆叠的替换使用[]将按顺序替换。它将经过column3三次,并分别执行每个替换。因此,在第一轮中被替换的东西有可能在下一轮中被替换。
https://fmhelp.filemaker.com/help/16/fmp/en/index.html#page/FMP_Help/substitute.html
,J布朗的答案是正确的。另外,您可以在单个Let函数中进行3次替换,如下所示:
Let ( [
_input_text = column3;
_sub1 = Substitute(_input_text; “AAA” ; “Acme” );
_sub2 = Substitute(_sub1; “AAA” ; “Acme” );
_sub3 = Substitute(_sub2; “AAA” ; “Acme” );
_output_text = _sub3
] ;
_output_text
)