Reputation: 129
How to eliminate the desired character & all the other characters succeeding that desired character.
def str1 = "value_of_string*123456"
Here, desired character is "*"
, and post desired character is "123456"
.
So, after removing them str1
should look like "value_of_string"
Upvotes: 0
Views: 69
Reputation: 50245
def str1 = "value_of_string*123456"
assert str1.takeWhile { it != '*' } == 'value_of_string'
assert str1.tokenize('*')[0] == 'value_of_string'
assert str1.split("\\*")[0] == 'value_of_string'
Upvotes: 2