【问题标题】:How to get substring in the given string from Robot Framework?如何从机器人框架中获取给定字符串中的子字符串?
【发布时间】:2020-09-10 18:03:20
【问题描述】:

给定字符串“显示 3,311 个条目中的 1 到 10 个”。我需要从该字符串中单独获取 3,311。我可以使用这个${Number} = Get Substring ${countString} 19 24,但这里的问题是索引已更改。

【问题讨论】:

  • 看看正则表达式。

标签: automation robotframework web-testing


【解决方案1】:

您可以使用Split String 关键字并将字符串的每个部分用${SPACE} 分隔
另外,我从号码中删除了,,以防万一。实现相同的方式略有不同 - https://stackoverflow.com/a/57786634/5400362

*** Variable ***
${string1}=        Showing 1 to 10 of 3,311 entries

*** Testcases ***
Get Number From String

@{list_string}=     split string    ${string1}      ${SPACE}
log             ${list_string}[5]
${num}=         evaluate       '${list_string}[5]'.replace(',','')

输出

【讨论】:

    猜你喜欢
    • 2020-11-30
    • 2012-02-10
    • 1970-01-01
    • 2022-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    • 2021-01-29
    相关资源
    最近更新 更多