9

Robot Framework の使用中に文字列から空白をトリムまたは除去する方法

文字列 "Hello How are you" を "HelloHowareyou" に変換する方法 (すべての空白を削除)

4

4 に答える 4

21

${str.strip()} も機能します。拡張変数構文を使用します例:

*** Variables ***
${str}=    ${SPACE}${SPACE}${SPACE}foo${SPACE}${SPACE}${SPACE}

*** Test cases ***
print string
    log    ${str}         # will be printed with spaces around it
    log    ${str.strip()} # will be printed without spaces around it

pybot -L TRACE で実行して、log キーワードに何が渡されているかを確認します。

于 2013-07-30T13:07:09.183 に答える
4
${time_stamp}=       Get Time
${time_stamp}=       Evaluate    '${time_stamp}'.replace(' ','_')

役に立つこともある

于 2016-09-28T21:14:38.633 に答える
3

これは、python 関数または正規表現を使用して行うことができます。

MyLibrary.py

def Remove_Whitespace(instring):
    return instring.strip()

MySuite.txt

| *Setting* | *Value* |
| Library   | String        
| Library   | ./MyLibrary.py

| *Test Case* | *Action* | *Argument*
| T100 | [Documentation] | Removes leading and trailing whitespace from a string.
       # whatever you need to do to get ${myString}
|      | ${tmp}= | Remove Whitespace | ${myString}
       # ${tmp} is ${myString} with the leading and trailing whitespace removed.
| T101 | [Documentation] | Removes leading and trailing whitespace from a string.
       # whatever you need to do to get ${myString}
       # The \ is needed to create an empty string in this format
|      | ${tmp}= | Replace String Using Regexp | ${myString} | (^[ ]+|[ ]+$) | \
       # ${tmp} is ${myString} with the leading and trailing whitespace removed.
于 2013-07-24T15:52:42.697 に答える