Skip to Content
0

Need groovy script to remove the string suffix

Dec 02, 2017 at 03:34 PM

64

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Muniyappan Marasamy Dec 05, 2017 at 04:52 AM
0

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)
Share
10 |10000 characters needed characters left characters exceeded