Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting String with delimiter

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?

like image 625
thehoule64 Avatar asked May 08 '13 21:05

thehoule64


People also ask

How do you delimiter a string?

Using String. split() Method. The split() method of the String class is used to split a string into an array of String objects based on the specified delimiter that matches the regular expression.

How do you split a string into characters?

Split is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters.


1 Answers

Try:

def (value1, value2) = '1128-2'.tokenize( '-' ) 
like image 192
tim_yates Avatar answered Sep 20 '22 14:09

tim_yates