Slice a string in groovy

前端 未结 3 582
长情又很酷
长情又很酷 2021-01-07 16:46

I have a 18 character string I want characters 2-8 from. In python I can do this:

sliceMe = \"nnYYYYYYnnnnnnnnnn\"
print sliceMe[2:8]

prin

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 17:07

    groovy:000> sliceMe = "nnYYYYYYnnnnnnnnnn"
    ===> nnYYYYYYnnnnnnnnnn
    groovy:000> sliceMe[2..7]
    ===> YYYYYY
    

    Note the difference in the length being 1 less.

提交回复
热议问题