Splitting strings [rookie]

2,251 views
Skip to first unread message

Manuel González

unread,
Jan 28, 2016, 11:46:32 AM1/28/16
to robotframework-users
Hello everyone, I'm new using robotframework and python language and I'm having issues splitting a string. I have this string:

{u'ticket': {u'id': u'502-07385089-741'}}

I want to erase the first and the last character ( { and } ) using the keywords Split string and Split string from right (maybe there are better and more elegant ways to do it but as I said in the subject I'm a rookie, sorry). In the documentation I see this

Name:  Split String
Source: String <test library>
Arguments: [ string | separator=None | max_split=-1 ]

This is what I wrote (i've tried many ways but this is the most logical for me), remember i just want to erase the first element, the '{'

${splitted_string}=     Split String     ${string}      {        1


This is the fail i receive:
20160128 17:05:46.958 :  FAIL : AttributeError: split


I'm going crazy, I don't want to try another way to do it because this has become a personal matter hahahahah, i need your help guru's!!

Sorry for my incorrect writting skills, I'm not very good at English, and of course, thank you all!

Pekka Klärck

unread,
Jan 28, 2016, 12:40:39 PM1/28/16
to fdw....@gmail.com, robotframework-users
2016-01-28 18:32 GMT+02:00 Manuel González <fdw....@gmail.com>:
> Hello everyone, I'm new using robotframework and python language and I'm
> having issues splitting a string. I have this string:
>
> {u'ticket': {u'id': u'502-07385089-741'}}

Are you sure it is a string not a dictionary (i.e. map) with that
string representation? The reason I suspect it may not be a string is
that the AttributeError you got:

> ${splitted_string}= Split String ${string} { 1
>
> This is the fail i receive:
> 20160128 17:05:46.958 : FAIL : AttributeError: split

If ${string} would really be a string, it would also have `split` method.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

pra...@datatorrent.com

unread,
Jan 29, 2016, 12:22:53 AM1/29/16
to robotframework-users
If that's the way you want it, here it is:

*** Settings ***
Library           String
Library           Collections

*** Test Cases ***
Remove First And Last Char
    ${string}=    Set Variable    {u'ticket': {u'id': u'502-07385089-741'}}
    @{splitted_string}=    Split String    ${string}    {    1
    ${string}=    Get From List    ${splitted_string}    1
    Log    ${string}
    @{splitted_string}=    Split String From Right    ${string}    }    1
    ${string}=    Get From List    ${splitted_string}    0
    Log    ${string}


Reply all
Reply to author
Forward
0 new messages