Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split strings from a line in robot framework

How to get rest of the values from the variable

${random employee}= Convert To String   ${random emp}   
${replace}= Remove String Using Regexp  ${random employee}  ['\\[\\]\\,]

${splitline}=   Fetch From Left ${replace}  ${SPACE}

Output:

${replace} Alagu [email protected][email protected] Developer Team B3 Team lead

${splitline} = Alagu

How to get rest of the values from the variable ${replace}

like image 649
karthika s Avatar asked Sep 28 '15 10:09

karthika s


People also ask

How do you split text in robot framework?

Splits the string using separator as a delimiter string. If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored. Split words are returned as a list.

How do you trim spaces in Robot Framework?

Run with pybot -L TRACE to see what is being passed to log keyword. This only removes spaces around it. Since Robotframework 3.0 this can also be done with Strip String in the String library. To remove all spaces from the string use the solution from Grant McCloskey.


1 Answers

Keyword Split String from String standard library does this.

Split String    string, separator=None, max_split=-1

Splits the string using separator as a delimiter string.

If a separator is not given, any whitespace string is a separator. In that case also possible consecutive whitespace as well as leading and trailing whitespace is ignored.

Split words are returned as a list. If the optional max_split is given, at most max_split splits are done, and the returned list will have maximum max_split + 1 elements.

Examples:

@{words} =  Split String    ${string}           
@{words} =  Split String    ${string}       ,${SPACE} 

To get single values from @{words} use common array syntax: @{NAME}[i]. i is the index of the selected value. Indexes start from zero.

like image 127
Psytho Avatar answered Jan 01 '23 08:01

Psytho