我在groovy中有一个字符串pRoiGroup="[com.testing.Location#533bfa78d3f9645043e4eb25]"
。我想从"533bfa78d3f9645043e4eb25"
获取字符串pRoiGrop
。我可以知道实现目标的正确方法是什么?也许这个问题太基础了,但我找不到合适的解决方案。请帮帮我。
答案 0 :(得分:0)
也许是这样的?
def pRoiGroup = "[com.testing.Location#533bfa78d3f9645043e4eb25]"
def part = pRoiGroup.tokenize("#")[1].replaceAll("]", "")
println part
答案 1 :(得分:0)
简单直接
As Array
def pRoiGroup="[com.testing.Location#533bfa78d3f9645043e4eb25]"
def string = pRoiGroup.split('#')
def finalString = string[1].replace("]", "")
// finalString will be 533bfa78d3f9645043e4eb25
或者像这个答案那样做一个ArrayList:https://stackoverflow.com/a/22906303/2414129
def pRoiGroup="[com.testing.Location#533bfa78d3f9645043e4eb25]"
def resultList = pRoiGroup.tokenize('#')
def finalString = resultList.get(1).replace("]", "")