groovy How to extract string?

Viewed 22

(groovy) I have a string like "1.2.3" and I have to extract the substring before the last "." for example "1.2" . I tried some split('.'), tokenize('.'), but they don't work.

1 Answers

How about the below?

def v = "1.2.3"
v.substring(0, v.lastIndexOf("."))
Related