Groovy 安全线片

Groovy 安全线片,groovy,Groovy,我有一个字符串,我想要250个字符或更少。我是用java的方式做的,但是有没有groovy的快捷方式: 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.

我有一个字符串,我想要250个字符或更少。我是用java的方式做的,但是有没有groovy的快捷方式:

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) 
def longString="这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串。这是我的非常长的字符串长字符串。这是我的真长字符串。这是我的真长字符串。这是我的真长字符串。这是我的真长字符串。这是我的真长字符串。这是我的真长字符串。”
def shortString=“这是我真正的短字符串。”
#理想的情况是:
返回长字符串[0..250]
#和我现在的情况相比
#我如何简化这个。。。
返回shortString.size()<250?shortString:shortString.substring(0250)

String shortString = longString.take( 250 )