cancel
Showing results for 
Search instead for 
Did you mean: 

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

anurag_sinha3
Participant
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
Active Contributor
0 Kudos

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

Answers (0)