How to trim or erase spaces from a string when using Robot Framework

How to crop or erase white spaces from a string when using Robot Framework

If I have the line "Hello How are you" how to convert it to "HelloHowareyou" (removing all spaces)

+7
source share
4 answers

$ {Str.strip ()} also works. It uses advanced variable syntax Example:

*** 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 

Run with pybot -L TRACE to find out what is being passed to the log keyword.

+17
source
 ${time_stamp}= Get Time ${time_stamp}= Evaluate '${time_stamp}'.replace(' ','_') 

Perhaps also useful

+4
source

You can do this with the python function or with regular expressions.

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. 
+1
source

Delete the line ${SPACE} ${SPACE} ${SPACE}

0
source

Source: https://habr.com/ru/post/950169/


All Articles