在groovy中使用grails从另一个字符串提取子字符串
我在groovy中有一个字符串在groovy中使用grails从另一个字符串提取子字符串,groovy,Groovy,我在groovy中有一个字符串pRoiGroup=“[com.testing.Location#533bfa78d3f9645043e4eb25]”。我想从pRoiGrop获取字符串“533bfa78d3f9645043e4eb25”。我可以知道实现我的目标的正确方法是什么吗?也许这个问题太基本了,但我没有找到任何合适的解决方案。请帮助我。也许类似这样的问题 def pRoiGroup = "[com.testing.Location#533bfa78d3f9645043e4eb25]" def
pRoiGroup=“[com.testing.Location#533bfa78d3f9645043e4eb25]”
。我想从pRoiGrop
获取字符串“533bfa78d3f9645043e4eb25”
。我可以知道实现我的目标的正确方法是什么吗?也许这个问题太基本了,但我没有找到任何合适的解决方案。请帮助我。也许类似这样的问题
def pRoiGroup = "[com.testing.Location#533bfa78d3f9645043e4eb25]"
def part = pRoiGroup.tokenize("#")[1].replaceAll("]", "")
println part
朴素 As数组
def pRoiGroup="[com.testing.Location#533bfa78d3f9645043e4eb25]"
def string = pRoiGroup.split('#')
def finalString = string[1].replace("]", "")
// finalString will be 533bfa78d3f9645043e4eb25
或者作为ArrayList这样做,答案如下:
可能重复的
def pRoiGroup="[com.testing.Location#533bfa78d3f9645043e4eb25]"
def resultList = pRoiGroup.tokenize('#')
def finalString = resultList.get(1).replace("]", "")