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.  extract from a string

    Employee
    Posted 02-09-2015 04:59

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

    Originally posted by: dhrobertson

    Hi I am looking for a good way to extract data from a string value.
    below is the example I have. I want to extract WUK02013946085 from the string below in an elegant, repeatable manner...
    I tried using a split with not much luck and have ended up with the script below:

    original field name is PLACEID with value of:
    WUKR00104389WUK02013946085

    brainscript:
    temp1 = replace(PLACEID,left(PLACEID,12),"")

    temp1:
    WUK02013946085

    my potential issue is if the initial part of the string is not always 12 characters in length... then it will throw it out.
    is there a better way to reliably extract WUK02013946085 from the original string, every time?

    thanks

    doug


  • 2.  RE: extract from a string

    Employee
    Posted 02-09-2015 06:33

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

    Originally posted by: ryeh

    So are you only trying to extract characters from the 13th position onwards? If so, then something like:

    if n >= 12
    then temp1 = PLACEID.substr(12)
    else temp1 = PLACEID


  • 3.  RE: extract from a string

    Employee
    Posted 02-09-2015 07:50

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

    Originally posted by: stonysmith

    This bit of code would probably do what you need:

    leftpart=left(PLACEID,3)                        #get the repeating portion
    position=strFind(substr(PLACEID,2),leftpart)+2   #find where it repeats
    leftpart=left(PLACEID,position)                         #split off the left side
    rightpart=substr(PLACEID,position)                    #split off the right side
    emit PLACEID,leftpart,rightpart,position


  • 4.  RE: extract from a string

    Employee
    Posted 02-10-2015 04:21

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

    Originally posted by: dhrobertson

    thanks all for the response. appreciate the help


  • 5.  RE: extract from a string

    Employee
    Posted 02-10-2015 05:10

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

    Originally posted by: dhrobertson

    Originally posted by: stonysmith
    					

    This bit of code would probably do what you need:

    leftpart=left(PLACEID,3)                        #get the repeating portion
    position=strFind(substr(PLACEID,2),leftpart)+2   #find where it repeats
    leftpart=left(PLACEID,position)                         #split off the left side
    rightpart=substr(PLACEID,position)                    #split off the right side
    emit PLACEID,leftpart,rightpart,position

    What I have gone with in the end based on your example above (thanks very much by the way!) is as follows:

    leftpart=left(PLACEID,3) # get repeating string
    subset = substr(PLACEID,3) # get field, minus the first repeating string
    position = strFind(subset, leftpart) # get the offset position of the second repeating string
    offset= subset.len()- position # find the start of the new field by subtracting the offset position from the field length to give the start of the new field
    final = right(subset,offset) # take from the right based on value of offset

    I think this should be repeatable each time as long as the repeating part is always 3 characters in length, which in my case it should be.