如何在第一次循环迭代后获取更改的内容(字符串)以用于机器人框架的下一次迭代
How to get the changed content (string) after first loop iteration to be used in next iteration in Robot framework
我有一个字符串列表,其中指定的部分应该替换为另一个。
String_01:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186577666'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+26+000000'
String_02:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186578112'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+26+000000'
String_03:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186601036'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+66+000000'
然后我有一个字典键,其中包含应该替换的内容,值具有新值。
&{PO_PAIRS} 186577666=4500000842 186578112=4500000843 186601036=4500000844
现在我用字典遍历每个字符串。如果从字符串中找到字典键,则将其更改为字典值。
NewString
[Arguments] ${string}
FOR ${key} IN @{PO_PAIRS}
${value} = Get from dictionary ${PO_PAIRS} ${key}
${changed_string} = Replace string ${string} ${key} ${value}
END
[Return] ${changed_string}
问题是在循环的第一次迭代之后,${changed_string}
应该是下一次迭代的起点而不是 ${string}
。有什么方法可以为循环中的下一次迭代设置 ${changed_string}
吗?
problem is that after first iteration of the loop, the ${changed_string}
should be the starting point for the next iteration instead of ${string}
是的,在每次迭代中您都在重新定义 ${changed_string}
,因此最后 ${string}
只是最后一次更改。
不要使用中间变量,将替换后的字符串重新分配给${string}
,并且return它:
NewString
[Arguments] ${string}
FOR ${key} IN @{PO_PAIRS}
${value} = Get from dictionary ${PO_PAIRS} ${key}
${string} = Replace string ${string} ${key} ${value}
END
[Return] ${string}
我有一个字符串列表,其中指定的部分应该替换为另一个。
String_01:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186577666'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+26+000000'
String_02:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186578112'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+26+000000'
String_03:
UNH+000000'
BGM+ZLI+000000'
DTM+3:20210430:102'
RFF+AFL:000000'
RFF+CO:186601036'
RFF+PK:000000'
MOA+125:000000'
MOA+150:000000'
UNT+66+000000'
然后我有一个字典键,其中包含应该替换的内容,值具有新值。
&{PO_PAIRS} 186577666=4500000842 186578112=4500000843 186601036=4500000844
现在我用字典遍历每个字符串。如果从字符串中找到字典键,则将其更改为字典值。
NewString
[Arguments] ${string}
FOR ${key} IN @{PO_PAIRS}
${value} = Get from dictionary ${PO_PAIRS} ${key}
${changed_string} = Replace string ${string} ${key} ${value}
END
[Return] ${changed_string}
问题是在循环的第一次迭代之后,${changed_string}
应该是下一次迭代的起点而不是 ${string}
。有什么方法可以为循环中的下一次迭代设置 ${changed_string}
吗?
problem is that after first iteration of the loop, the
${changed_string}
should be the starting point for the next iteration instead of${string}
是的,在每次迭代中您都在重新定义 ${changed_string}
,因此最后 ${string}
只是最后一次更改。
不要使用中间变量,将替换后的字符串重新分配给${string}
,并且return它:
NewString
[Arguments] ${string}
FOR ${key} IN @{PO_PAIRS}
${value} = Get from dictionary ${PO_PAIRS} ${key}
${string} = Replace string ${string} ${key} ${value}
END
[Return] ${string}