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 a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on 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('_')));
    


    groovy.jpg (60.2 kB)
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.