Groovy按周期分割,仅返回第一个值 [英] Groovy split on period and return only first value
本文介绍了Groovy按周期分割,仅返回第一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的输入为
var = primarynode.domain.local
,现在我只需要primarynode
.
我一直在查看拆分和标记化,但无法在一行代码中完成.有谁知道如何在一行代码中做到这一点?
I was looking both split and tokenize but not able to do it in one line code. does anyone know how to do it in one line code?
推荐答案
假设您只想获得第一个单词(在
.
之前) 从输入字符串中获取.
Well assuming that you want to just get the first word(before
.
) from the input string.
您可以使用字符串的tokenize
运算符
You can use the tokenize
operator of the String
如果有
def var = "primarynode.domain.local"
那么您就可以
def firstValue = var.tokenize(".")[0]
println firstValue
输出
primarynode
这篇关于Groovy按周期分割,仅返回第一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文