如何使用机器人框架从字符串中获取特定文本?

问题描述

我需要使用robotframework从字符串中获取':'之前的数字,怎么办?

${str}=    Set Variable  7939:customer-Id:123a34ghas

我只需要在之前得到 7939 ,如何在机器人框架中实现?

${Id}=   split string ${str}
log to console   ${Id} #Should give only 7939

解决方法

${str}=    Set Variable    7939:customer-Id:123a34ghas

${Id}=    split string    ${str}    :

log to console    ${Id}[0]    #prints 7939