Skip to Content

Need groovy script to remove the string suffix

Dear Experts,

i have a requirement where i need to remove the suffix from the input value and pass it to the target field. For example i am getting the values 101_1,101_2,101_3,101_4,AB_1 etc from the source.Now i need to pass the value like 101 for each input value as an output for each input value and for AB_1 need AB as output value. we are having multiple values like this so i need to remove the the value _followed by number.Please help me on this.

Regards

Giridhar Vegi.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Dec 05, 2017 at 04:52 AM

    didn't you try split or substring function? google it.

    String testString = '101_1';
    String testString1 = 'AB_1';
    String[] out = testString.split('_');
    String[] out1 = testString1.split('_');
    println out[0];
    println out[1];
    
    
    println"=============================";
    
    
    println out1[0];
    println out1[1];
    
    
    println"==============SubString===============";
    
    
    //def out2 = testString.indexOf('_');
    
    
    println(testString.substring(0,testString.indexOf('_')));
    println(testString1.substring(0,testString1.indexOf('_')));
    

    Add comment
    10|10000 characters needed characters exceeded