Slice a string in groovy

点点圈 提交于 2019-12-01 15:35:44
groovy:000> sliceMe = "nnYYYYYYnnnnnnnnnn"
===> nnYYYYYYnnnnnnnnnn
groovy:000> sliceMe[2..7]
===> YYYYYY

Note the difference in the length being 1 less.

BZ.

You inherit all the Java methods off String so sliceMe.substring(2,7) should do the trick.

For future reference, you can compare the "Programming Language Examples Alike Cookbook" strings methods if you are unclear on how something is written in Python versus Groovy (or other syntaxes).

Here are the slicing python strings http://pleac.sourceforge.net/pleac_python/strings.html

And here are the slicing groovy strings: http://pleac.sourceforge.net/pleac_groovy/strings.html

Check the table of contents if you need to see other comparisons, its a good reference.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!