Python 在机器人框架中连接两个字符串的最简单方法。?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46539759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:41:03  来源:igfitidea点击:

Simplest way to concatenate two strings in robot framework .?

pythonrobotframeworkrobotframework-ide

提问by user3170122

Given two strings 'a' , 'b', what is the simplest way to concatenate them and assign to a new variable in robot framework.?

给定两个字符串 'a' , 'b' ,在机器人框架中连接它们并分配给新变量的最简单方法是什么?

I tried this simple pythonic way, but it didn't work

我尝试了这种简单的pythonic方式,但没有用

${var}= 'a' + 'b'

回答by Oleh Rybalchenko

You can use Catenatefrom BuiltIn.

您可以使用链状BuiltIn

Example from docs:

来自文档的示例:

${str1} =   Catenate    Hello   world   
${str2} =   Catenate    SEPARATOR=---   Hello   world
${str3} =   Catenate    SEPARATOR=  Hello   world
=>
${str1} = 'Hello world'
${str2} = 'Hello---world'
${str3} = 'Helloworld'

回答by Todor Minakov

Catenateis the usual way to go with strings, as pointed in the other answer.
Alternative option is to use just Set Variable:

Catenate正如另一个答案中所指出的那样,是使用字​​符串的常用方法。
另一种选择是只使用Set Variable

${a}=    Set Variable   First
${b}=    Set Variable   Second

${c}=    Set Variable   ${a}${b}
Log To Console    ${c}    # prints FirstSecond

${c}=    Set Variable   ${a} ${b}
Log To Console    ${c}    # prints First Second

${c}=    Set Variable   ${a}-/-${b}
Log To Console    ${c}    # prints First-/-Second

The explaination is that the RF processing of any keyword's arguments - Set Variableincluding, goes through substituting any variable with its value. E.g. for this call:

解释是任何关键字参数的 RF 处理 -Set Variable包括,通过用其值替换任何变量。例如对于这个电话:

Set Variable   ${a}-/-${b}

What roughly happens is "the end value is the value of variable a-/-the value of variable b".

大致发生的是“最终值是变量的值a-/-变量的值b”。