I have a String that I want 250 chars or less. I was doing it the java way, but is there a groovy shortcut for this:
def longString = "This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string.This is my really long string."
def shortString = "This is my really short string."
#ideal would be something like:
return longString[0..250]
#versus how i currently have it
#how can i simplify this one...
return shortString.size() < 250? shortString: shortString.substring(0,250)
You can use take
:
String shortString = longString.take( 250 )
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