LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  delimit a column on [

    Employee
    Posted 03-12-2013 10:20

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: svimes

    Hi i have a column of data which is of the form string1 [string2].

    String 1 and String 2 vary. In addition a few of the rows do not have [string2] they just have string1 and no square brackets.

    I wanted to get string 1 and string 2 in separate columns, labelled PRODUCT _GROUP and PRODUCT respectively so I did:

    split_field = string1.split("[")
    PRODUCT_GROUP = string1.getItem(0).trim()

    which is fine to get string 1.

    However if i do

    PRODUCT_GROUP = string1.getItem(1)

    I get an index out of bounds error which I suspect is due to some rows not have an item(2) as it has no "[" character to split on. What's the way round this and am I doing this in the most efficient way? Thanks


  • 2.  RE: delimit a column on [

    Employee
    Posted 03-15-2013 13:11

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rboccuzzi

    Sure, you could do:

    split_field = string1.split("[")
    PRODUCT_GROUP = split_field[0].trim()
    if len(split_field) > 1 then
    PRODUCT = split_field[1].split("]")[0].trim()
    else
    PRODUCT = null

    emit PRODUCT, PRODUCT_GROUP

    Cheers
    Rich