我有一个字符串,我想要 250 个字符或更少。我是用java的方式做的,但是有没有一个时髦的捷径:
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)