title: Groovy - Split by hyphen '-' and concatenate values at index 1 and 2. if index 2 does not exist. return index 1 values only
body: <p>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.</p>
  <p>input 111-222-333 - should return 222333 as output.</p>
  <p>input 111-222 - should only return 222 as output.</p>
  <pre><code>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(&quot;-&quot;);
  {
      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];
      }
  }
  }
  </code></pre>
  <p>Thanks,
  Vicky.</p>