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?
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.
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.
Try:
def (value1, value2) = '1128-2'.tokenize( '-' )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With