on 2021 Aug 19 12:25 PM
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
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
7a519509aed84a2c9e6f627841825b5a You are fast by 45 seconds 🙂 It took couple of min for me to open Groovy Console 🙂
Hey Morton,
thank you for your fast answer. It worked very well.
Have a nice day 🙂
Regards
Tim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
41 | |
15 | |
10 | |
9 | |
6 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.