我有一个Groovy方法,目前有效,但看起来很丑陋/ hacky:
def parseId(String str) { System.out.println("str: " + str) int index = href.indexOf("repositoryId") System.out.println("index: " + index) int repoIndex = index + 13 System.out.println("repoIndex" + repoIndex) String repoId = href.substring(repoIndex) System.out.println("repoId is: " + repoId) }
当它运行时,您可能得到如下输出:
str: wsodk3oke30d30kdl4kof94j93jr94f3kd03k043k?planKey=si23j383&repositoryId=31850514 index: 59 repoIndex: 72 repoId is: 31850514
如您所见,我只是想从String中获取repositoryId值(在=运算符之后的所有内容).有没有更有效/更多的方式来做这个或这个唯一的方法?