Splitting String with delimiter

thehoule64 picture thehoule64 · May 8, 2013 · Viewed 246.3k times · Source

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?

Answer

tim_yates picture tim_yates · May 8, 2013

Try:

def (value1, value2) = '1128-2'.tokenize( '-' )