cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

sap cpi message mapping string split

0 Kudos
3,012

Hello,

I have a problem with my groovy script. I want to split a string on the character "|". If I try to split on this character,

the function always splits the string after the first character of the string. If I try to split on a letter or a number it works perfectly.

I already tried ASCII but it didnt work eather.

This is my code from the thread:

https://answers.sap.com/questions/13121983/sap-cpi-split-a-string-at-delimiter-and-add-contex.html

def void addContextChange(String[] input, Output output, MappingContext context) { 
    for(item in input[0].split('|')){
     output.addValue(item);
    }
}

I hope someone can help me 🙂

Greetings

Tim

Accepted Solutions (1)

Accepted Solutions (1)

MortenWittrock
SAP Mentor
SAP Mentor

Hi Tim

The split method expects a regular expression, and the pipe (|) has special meaning in regular expressions, so to split on the pipe, you need to escape it like this:

split('\\|')

Regards,

Morten

Sriprasadsbhat
Active Contributor

7a519509aed84a2c9e6f627841825b5a You are fast by 45 seconds 🙂 It took couple of min for me to open Groovy Console 🙂

Answers (1)

Answers (1)

0 Kudos

Hey Morton,

thank you for your fast answer. It worked very well.

Have a nice day 🙂

Regards

Tim