1

I'm using Xtend template to generate list and I would like to pop-off the last comma from the generated sequence:

«FOR link : links»
«link.simpleName»,
«ENDFOR»

Can I manipulate the StringConcatenation behind "on-the-fly"?

«ENDFOR _builder.deleteCharAt(result.size - 1)»

The sample above is not possible, StringConcatenation does not have such a method.

Adam Horvath
  • 1,249
  • 1
  • 10
  • 25

1 Answers1

1

Loops in templates support additional keywords to add characters before and after the loop and between elements.

You can use SEPARATOR to avoid the trailing comma:

«FOR link : links SEPARATOR ','»
«link.simpleName»
«ENDFOR»
kapex
  • 28,903
  • 6
  • 107
  • 121