当我向此函数提供string stknummer =“* VU-NR:-93.10xxxxxxxx_2-12-2011 *”时:
whileprintingrecords;
shared stringvar tstnummer;
shared stringvar stknummer;
local stringvar tst;
local stringvar stk;
local stringvar bc;
tst := tstnummer;
stk := stknummer;
//why is this not evaluated?
tst := Replace (tstnummer,":" ,"_" );
tst := Replace (tstnummer,"." ,"_" );
tst := Replace (tstnummer,"=" ,"_" );
tst := Replace (tstnummer,"/" ,"_" );
tst := Replace (tstnummer,"\" ,"_" );
tst := Replace (tstnummer,"?" ,"_" );
tst := Replace (tstnummer,"#" ,"_" );
tst := Replace (tstnummer,"." ,"_" );
tst := Replace (tstnummer,"*" ,"_" );
tst := Replace (tstnummer,"|" ,"_" );
tst := Replace (tstnummer,"<" ,"_" );
tst := Replace (tstnummer,">" ,"_" );
tst := Replace (tstnummer," " ,"-" );
//and this neither?
stk := Replace (stknummer,":" ,"_" );
stk := Replace (stknummer,"." ,"_" );
stk := Replace (stknummer,"=" ,"_" );
stk := Replace (stknummer,"/" ,"_" );
stk := Replace (stknummer,"\" ,"_" );
stk := Replace (stknummer,"?" ,"_" );
stk := Replace (stknummer,"#" ,"_" );
stk := Replace (stknummer,"." ,"_" );
stk := Replace (stknummer,"*" ,"_" );
stk := Replace (stknummer,"|" ,"_" );
stk := Replace (stknummer,"<" ,"_" );
stk := Replace (stknummer,">" ,"_" );
stk := Replace (stknummer," " ,"-" );
//select file output format
if {?barcode_type} = true
then (if trim(stk) =""
then
bc:= "*" + tst + "_" + totext(dateValue({@signdate})) + "*"
else
(
bc:= "*" + stk + "_" + totext(dateValue({@signdate})) + "*");;)
else bc := "*" + tst + "_" + totext(dateValue({@signdate})) + "*"
结果是没有替换(即:仍然存在)
当我将Replace(stk,“:”,“_”)放在底部函数中时:
//select file output format
if {?barcode_type} = true
then (if trim(stk) =""
then
bc:= "*" + tst + "_" + totext(dateValue({@signdate})) + "*"
else
(
bc:= "*" + Replace (stk, ":", "_") + "_" + totext(dateValue({@signdate})) + "*");;)
else bc := "*" + tst + "_" + totext(dateValue({@signdate})) + "*"
更换正确完成。
为什么在第一个例子中没有完成替换?
我很好地将所有替换品都放在了这个功能中,但这并不是太优雅......
感谢
答案 0 :(得分:3)
哦,你会对这个感到生气:)
正在评估Replace()函数...但是每次只用一次替换原始字符串 tstnummer和stknummer来覆盖变量stk和tst。当所有Replaces()完成后,你只需要留下一个没有空白字符的字符串。需要改变这个...
...
tst := Replace (tst,":" ,"_" );
tst := Replace (tst,"." ,"_" );
tst := Replace (tst,"=" ,"_" );
...
stk := Replace (stk,":" ,"_" );
stk := Replace (stk,"." ,"_" );
答案 1 :(得分:0)
+1 - 之前就抓住了我。
在第一次作业中,
tst := tstnummer;
你给'tst'一个值。
在您的第一个有效陈述中,
tst := Replace (tstnummer,":" ,"_" );
您正在为'tst'重新分配值。每个活动语句都会使用REPLACE()的结果重新分配'tst',该结果作用于'tstnummer'中的值。 'Tstnummer'永远不会改变。 'Tst'重复分配LAST REPLACE()
的结果相反,在为'tst'指定了一个值之后,你想要在变量'Tst'上用REPLACE()的结果重新赋值。每次处理活动语句时,都会更新'tst'的值,而NEXT活动语句将处理“new”'tst'。
这听起来令人困惑,但如果你单步执行它,你会看到。 'Tstnummer'保持不变
接下来我们将玩REGEX! (开玩笑)。