简体   繁体   中英

groovy How to extract string?

(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.

How about the below?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM