unknown
unknown

Reputation: 1893

Splitting String in specific pattern and remove the last digit in groovy

I have a value of one variable in this format version = 6.1.0.75. I am trying to write a logic in groovy/gradle to change the value of this string from 6.1.0.75 to 6_1_0

I want to remove the last digit (75) and keep first 3 digit 6.1.0 in 6_1_0 format. The value of the version variable could be anything.

Can someone tell how we can achieve this?

I need to do the same thing in groovy:

a = 1.2.3.67890
echo $a | cut -d "." -f1,2,3 | tr "." "_"

gives:

1_2_3

Upvotes: 2

Views: 301

Answers (1)

Opal
Opal

Reputation: 84756

Just try:

'6.1.0.75'.split('\\.')[0..-2].join('_')

Upvotes: 2

Related Questions