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.  A split problem

    Employee
    Posted 01-19-2016 08:37

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

    Originally posted by: Staven

    Hello fellow Lavastormers,

    As a newbie in the world of Lavastorm I'm facing a for me rather challenging situation.

    Staying away from the content of the why, below is what I'm dealing with.

    I have multiple records such as the following in one field:

    Field_A
    string_a\r\nstring_b\r\n\r\nstring_c\r\nstring_d\r \nstring_e
    string_a\r\n\r\n\r\nstring_b\r\nstring_c\r\nstring _d


    I want to reduce the strings in Field_A to a list based on the delimiter: \r\n, and as you can see the number of \r\n between two strings is variable.

    Can anyone advice me how to proceed? (namely how to reduce the occurance of multiple delimiters between two string to one delimiter between two strings)

    Thank you very much!


  • 2.  RE: A split problem

    Employee
    Posted 01-19-2016 08:48

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

    Originally posted by: stonysmith

    A big question would be.. what do you want the output to be?

    Do you want the "string b" to be in the same output column each time?

    Try this code:
    x=myInputString.replace("\r","")   #remove carriage returns
    x=x+"\n\n\n\n\n\n"                    # add extra separators to ensure split does not fail
    x=x.split("\n")
    emit x[0] as column_0
    emit x[1] as column_1
    emit x[2] as column_2
    emit x[3] as column_3
    emit x[4] as column_4


  • 3.  RE: A split problem

    Employee
    Posted 01-19-2016 14:43

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

    Originally posted by: Staven

    stony,

    Thank you very much for your reply.

    The solution you provide does unfortunately not cover that which I seek, due to the fact that the number of strings I wish to extract from the record is variabele as well.

    The solution that I seek is to create a list of the strings. Normally that would be achieved by using the reduce to list node.
    An example:

    Field_A
    string_a|string_b|string_c|string_d|string_e
    string_a|string_b|string_c|string _d

    Using the reduce to list with pipe as seperator would result in:

    FieldA
    string_a
    string_b
    string_c
    string_d
    string_e
    string_a
    string_b
    string_c
    string_d

    So what I would like to do is remove the string \r\n if it occurs multiple times after one another: make \r\n\r\n --> \r\n (occur once between each string).

    This could also mean first replacing \r\n with another single character, for example the pipe in the ideal example: \r\n --> | and then if | occurs > 1 between two string reduce it to 1 occurence between 2 strings:

    string_a|||string_b|string_c||||||string_d --> string_a|string_b|string_c|string_d

    Thing is, it also seems quite hard to replace \r\n with another character due to the \, somehow lavastorm doesn't like it.

    In other words:

    the number of strings to "transpose/reduce to list" per record is variable
    the occurence of the character to use as a delimiter is variable

    Solution:
    1. reduce the number of delimiters to one occurrence between each string
    2. use reduce to list to transpose the strings based on the delimiter

    Point 1 is that which I can't get done, solving that would be much appreciated !


  • 4.  RE: A split problem

    Employee
    Posted 01-19-2016 19:30

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

    Originally posted by: ryeh

    Try using regex, where you can specify number of occurrences you want to replace. In this case, I am replacing instances where \r\n shows up more than once with just one \r\n.
    Attachments:
    regexRepeatMatches.brg


  • 5.  RE: A split problem

    Employee
    Posted 01-20-2016 01:37

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

    Originally posted by: Staven

    ryeh, thank you very much! Exactly what I was looking for! Kudo's :D