I am currently trying to split a string 1128-2
so that I can have two separate values. For example, value1: 1128 and value2: 2, so that I can then use each value se
You can also do:
Integer a = '1182-2'.split('-')[0] as Integer
Integer b = '1182-2'.split('-')[1] as Integer
//a=1182 b=2
split doesn't work that way in groovy. you have to use tokenize...
See the docs:
http://groovy-lang.org/gdk.html#split()
How are you calling split
? It works like this:
def values = '1182-2'.split('-')
assert values[0] == '1182'
assert values[1] == '2'
def (value1, value2) = '1128-2'.split('-')
should work.
Can anyone please try this in Groovy Console?
def (v, z) = '1128-2'.split('-')
assert v == '1128'
assert z == '2'
dependencies {
compile ('org.springframework.kafka:spring-kafka-test:2.2.7.RELEASE') { dep ->
['org.apache.kafka:kafka_2.11','org.apache.kafka:kafka-clients'].each { i ->
def (g, m) = i.tokenize( ':' )
dep.exclude group: g , module: m
}
}
}
Try:
def (value1, value2) = '1128-2'.tokenize( '-' )