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.  SIMPLE QUESTION NEWBIE -substr one field

    Employee
    Posted 11-02-2009 07:26

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

    Originally posted by: harley.stack@cox.com

    Folks

    How can I trim from the front of the data in one field (of a data set with many fields,) just three characters. I need a substring, example formula might be substr(columnN,4,strlen(columnN))

    I need to take something of the form "01 WAC-0109932" and return "WAC-0109932"

    I need to know the form of the brainscript and what node to use - to return all the columns with just one column altered. I can do this with sql easy - how do I do it with BRE. Please attach screenshots if you can.

    Thank you.

    HARLEY


  • 2.  RE: SIMPLE QUESTION NEWBIE -substr one field

    Employee
    Posted 11-02-2009 07:33

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

    Originally posted by: ddonovan

    Hi Harley...

    To accomplish this, you can use a filter node. There are several functions available in BrainScript that might accomplish what you want. For the specific example that you gave below, you could use the substr() function in this manner:

    columnN.substr(3)

    Within an emit statement in a filter node, for example, you could do this:

    emit *, columnN.substr(3) as newColumn

    There are also left() and right() functions within BrainScript which take a single integer as an argument and return that number of characters from the left or right of the string, respectively.

    Hope this helps...


  • 3.  RE: SIMPLE QUESTION NEWBIE -substr one field

    Employee
    Posted 11-02-2009 07:40

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

    Originally posted by: rboccuzzi

    Harley, if you have a field, lets call it columnN, as in your above example, you would use a filter node, and your brainscript would be:

    result = substr('columnN', 3)
    override emit *, result as "columnN"
    The function substr takes as arguments the column to retrieve the substring of, the offset to start taking the substring, and optionally, the length of the substring.

    The result of the function is assigned to the result variable, and then that is emitted along with all the other fields of data (using the *). Because there is already a field called "columnN", you need to put an override in front of emit, to acknowledge that you are overriding a field that already existed.

    In the future, if you are looking for various string manipulation functions, remember that there is a list of string operators in the online help for you to peruse. You can get to them by the Help menu in BRE, choosing the BRAINscript help, which will open an IE browser. On the left of the browser, there will be an expandable table of contents, and you can look at all the string operators available to you there. Clicking on one will give you the details of its use, usually with examples.

    Cheers
    Rich


  • 4.  RE: SIMPLE QUESTION NEWBIE -substr one field

    Employee
    Posted 11-02-2009 09:27

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

    Originally posted by: harley.stack@cox.com

    That works.

    Thank you.