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.  Text to column

    Employee
    Posted 01-26-2010 18:15

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

    Originally posted by: Kelvin

    Hi there. I have 2 fields which have data which relate to each other depending on where it is held. eg

    Field 1 Field 2
    109LA01�999M1EC�1091X01 1.00�1.00�2.00

    I need to convert to

    Field1 Field 2
    109LA01 1.00
    999M1EC 1.00
    1091X01 2.00

    What is the best way of acheiveing this?
    Thanks Kelvin


  • 2.  RE: Text to column

    Employee
    Posted 01-26-2010 18:31

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

    Originally posted by: stonysmith

    Add a filter and paste in the code below. It should do what you need.

    Explaining this code will take a bit of doing. It uses a feature of brainscript called DO OUTPUT where you can write out any number of output records from each input record. Please check the Help files for more information.



    #########
    f1 = 'Field1'.split("�") #convert to array
    f2 = 'Field2'.split("�") #convert to array
    oField1="" #initial value
    oField2="" #initial value
    output 1 { #dummy output statement
    emit oField1
    emit oField2
    where false #must be false
    }
    i=0 #setup loop counter
    while i < len(f1) { #step thru items of the array
    oField1 = f1.getItem(i)
    oField2 = f2.getItem(i)
    do output 1 { #output one record for each item of the array
    emit oField1
    emit oField2
    }
    i=i+1 #index the loop
    }


  • 3.  RE: Text to column

    Employee
    Posted 01-26-2010 19:09

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

    Originally posted by: Kelvin

    Of Course!!!
    Thanks for that. I'll add it to my box of tricks