How to combine string?

3,982 views
Skip to first unread message

Winston Ma

unread,
Jan 13, 2014, 11:36:01 PM1/13/14
to robotframe...@googlegroups.com
I know how to combine string using Catenate. However I have no idea how to join these into one statement

Here is the python way:
age = 10
statement = 'You are %d years old' % age

How could I do string substitution? 

Thanks in advance

Tatu Aalto

unread,
Jan 14, 2014, 12:45:37 AM1/14/14
to winsto...@gmail.com, robotframework-users

Ugh

Here is a Robot Framework way:
${age}=    10
${statement}=    Catenate    You are    ${age}    years old

-Tatu

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/groups/opt_out.

Laurent Bristiel

unread,
Jan 14, 2014, 3:06:31 AM1/14/14
to robotframe...@googlegroups.com, winsto...@gmail.com
Hey,

if you need to use the catenated string only once (and so, you don't need to put it in a variable),
then you can simply do:
log  you are ${age} years old

Laurent Bristiel
http://laurent.bristiel.com/


Le mardi 14 janvier 2014 06:45:37 UTC+1, Tatu Aalto a écrit :

Ugh

Here is a Robot Framework way:
${age}=    10
${statement}=    Catenate    You are    ${age}    years old

-Tatu

On 14 Jan 2014 06:36, "Winston Ma" <winsto...@gmail.com> wrote:
I know how to combine string using Catenate. However I have no idea how to join these into one statement

Here is the python way:
age = 10
statement = 'You are %d years old' % age

How could I do string substitution? 

Thanks in advance

--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Winston Ma

unread,
Jan 14, 2014, 3:58:39 AM1/14/14
to robotframe...@googlegroups.com
Sorry what if I have multiple items to log/

e.g. 
age = 10
sex='female'
statement = 'You are %s, %d years old' % (sex, age)

Is there better way? 

Pekka Klärck

unread,
Jan 15, 2014, 7:00:05 AM1/15/14
to Winston Ma, robotframework-users
2014/1/15 Winston Ma <winsto...@gmail.com>
>
> As you mentioned backward compatibility is an issue here.

There are no real backwards compatibility issues. It's just that if we
add "Format String" so that it uses Python's new format syntax,
Python/Jython 2.5 versions won't be able to use it. This definitely
shouldn't harm existing tests, though.

> Currently Catenate works for me. But still I will look forward to your 'Format String' method.

It's true that Catenate and just using variables in strings solves
most of the normal use cases. That's one more good reason to wait
until we drop Python/Jython 2.5 support in general (hopefully in RF
2.9) and don't need to think can the new formatting syntax be used or
not.

Cheers,
.peke

PS: Added robotframework-users back to Cc.
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org
Reply all
Reply to author
Forward
0 new messages