本文介绍了用分隔符分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在尝试拆分一个字符串 1128-2
,以便我可以有两个单独的值,例如:value1:1128和value2:2,以便我可以使用每个值分开。我试过 split()
但没有成功。
I am currently trying to split a string 1128-2
so that I can have two separate values ex: value1:1128 and value2:2 so that I can then use each value separately. I have tried split()
but with no success. Is there a specific way grails handles this or a better way of doing it?
推荐答案
尝试:
def (value1, value2) = '1128-2'.tokenize( '-' )
这篇关于用分隔符分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!