jarrodhroberson
2/14/2014 - 3:33 AM

Truncate String in Groovy

Truncate String in Groovy

// this adds a "truncate(#)" method to String
String.metaClass.truncate = { len ->
    if (delegate == null) {return''}
    if (delegate.length() > len) {return delegate[0..(len - 2)] + "\u2026"}
    return delegate
}