简体   繁体   English

groovy 如何提取字符串?

[英]groovy How to extract string?

(groovy) I have a string like "1.2.3" and I have to extract the substring before the last "." (groovy)我有一个像“1.2.3”这样的字符串,我必须在最后一个“。”之前提取 substring。 for example "1.2".例如“1.2”。 I tried some split('.'), tokenize('.'), but they don't work.我尝试了一些 split('.')、tokenize('.'),但它们不起作用。

How about the below?下面的呢?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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