samedi 28 août 2021

Groovy - Split by hyphen '-' and concatenate values at index 1 and 2. if index 2 does not exist. return index 1 values only

Writing an Groovy script to Split by '-' and concatenate values at index 1 and 2. if index 2 does not exist. return index 1 value only. Can you pls help with the code below.

input 111-222-333 - should return 222333 as output.

input 111-222 - should only return 222 as output.

import com.sap.it.api.mapping.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def String split(String input,MappingContext context){
def output = input.split("-");
{
    if (output[2].exists()) // also tried the statement if (output[2] != null). and did not work.
    {
        return output[1]+ output[2];
    }
    else
    {
        return output[1];
    }
}
}

Thanks, Vicky.

Aucun commentaire:

Enregistrer un commentaire