fork download
  1. // How to truncate a string in groovy?
  2. // https://stackoverflow.com/a/15713996
  3. println "=== Original example ==="
  4. println "abscd adfa dasfds ghisgirs fsdfgf".take(10) //"abscd adfa"
  5. println ""
  6. println "=== .take() ==="
  7. println "It's groovy, man".take(4) //"It's"
  8. println "It's groovy, man".take(10000) //"It's groovy, man" (no exception thrown)
  9. println ""
  10. println "=== .drop() ==="
  11. println "It's groovy, man".drop(-15) //"n"
  12. println "It's groovy, man".drop(5).take(6) //"groovy"
  13.  
Success #stdin #stdout 1.94s 125308KB
stdin
Standard input is empty
stdout
=== Original example ===
abscd adfa

=== .take() ===
It's
It's groovy, man

=== .drop() ===
It's groovy, man
groovy