ro ra ro ra - 1 year ago 135
Groovy Question

Groovy split on period and return only first value

I have the input as

var = primarynode.domain.local

and now I Need only
from it.

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?

Answer Source

Well assuming that you want to just get the first word(before . ) from the input string.

You can use the tokenize operator of the String

If you have

def var = "primarynode.domain.local"

then you can do

def firstValue = ​var.tokenize(".")[0]​
println firstValue


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download