如何在机器人框架中将字符串拆分为字符串

时间:2019-11-27 05:27:59

标签: robotframework

我有${number} 123456789

如何对此进行拆分,以使输出类似于以下内容-

 *12345 6789*

1 个答案:

答案 0 :(得分:4)

APPROACH#1 -使用RF内置字符串和集合来解决此问题

*** Settings ***
Library           String
Library     Collections

*** Test Cases ***
Case1
        @{characters} = Split String To Characters      123456789
        LOG TO CONSOLE  ${characters}
        ${x} =  Get Slice From List     ${characters}   0       5
        LOG TO CONSOLE  ${x}
        ${s1}=  Evaluate  "".join($x)
        LOG TO CONSOLE  ${s1}

       ${x2} =  Get Slice From List     ${characters}   5       10
        LOG TO CONSOLE  ${x2}
        ${s2}=  Evaluate  "".join($x2)
        LOG TO CONSOLE  ${s2}

APPROACH#2 -使用RF内置评估来解决此问题

*** Settings ***
Library           String
Library     Collections

*** Test Cases ***
Case1
        LOG TO CONSOLE  USING ONLY MATHS
        ${result} =     Evaluate        123456789//10000
        LOG TO CONSOLE  ${result}

        ${result2} =     Evaluate        123456789%10000
        LOG TO CONSOLE  ${result2}