Skip to Content

UDF in HCI to get string, before third "|"

Hi

I need a udf (Groovy Script)to fetch all the value in string which comes before thirsd "|".. for eg if the value is coming "CRN-YB20-DNB-SEPSDK|3Fcomp|3Dmp|4mp6|io90 .. then fetch the value before 3rd "|" so result will be

CRM-XB10-DNB-SEPSDK

3Fcomp

3Dmp..

note - | may or may not come in string and All value should come in queue

All value should come in queue

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Feb 26, 2019 at 09:53 AM

    Hi Anurag

    What you need is fairly simple to accomplish in Groovy. Take a look at the following:

    def void splitByPipe(String[] input, Output output, MappingContext context) {
        input[0].tokenize('|').take(3).each { t ->
            output.addValue(t)
        }
    }

    The tokenize('|') method splits the input string, using the pipe as the delimiter. The take(3) method returns a new List, containing the first three elements of the List returned by tokenize('|'). The resulting strings are added to the queue.

    Regards,

    Morten

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.