I am currently trying to split a string 1128-2
so that I can have two separate values. For example, 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?
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Converting a string array to a byte array
- Grails External Configuration. Can't access to
- How to convert a string to a byte array which is c
相关文章
- JSP String formatting Truncate
- Selecting only the first few characters in a strin
- Using Spring Dynamic Languages Support from Groovy
- Python: print in two columns
- extending c++ string member functions
- Google app engine datastore string encoding proble
- How to measure complexity of a string?
- What is the limit in size of a Php variable when s
How are you calling
split
? It works like this:def (value1, value2) = '1128-2'.split('-')
should work.Can anyone please try this in Groovy Console?
You can also do:
split doesn't work that way in groovy. you have to use tokenize...
See the docs:
http://groovy-lang.org/gdk.html#split()
Try: