在xtend模板中进行循环,以在同一行中打印

时间:2021-06-23 02:04:26

So if I have

所以,如果我有

«FOR number: numbers»
    «number»
 «ENDFOR»

It will print every number in new line, how do I make it print numbers in the same line?

它将在新行中打印每个数字,如何在同一行中打印数字?

2 个解决方案

#1


Maybe not suitable for your usecase, but did you try

也许不适合您的用例,但您尝试过吗?

«FOR number: numbers»«number»«ENDFOR»

Another option is to use «numbers.join()»

另一种选择是使用«numbers.join()»

#2


The for loop construction

for循环结构

«FOR number: numbers»
    «number»
«ENDFOR»

has been mainly created to generates values on many lines. If you need to concatenate values on a single line, join() is a better option:

主要是为了在许多行上生成值而创建的。如果需要在一行上连接值,join()是更好的选择:

«numbers.join»

Shorter, cleaner, more clear. And you can also give a separator parameter

更短,更清洁,更清晰。您还可以提供分隔符参数

«numbers.join(", ")»

#1


Maybe not suitable for your usecase, but did you try

也许不适合您的用例,但您尝试过吗?

«FOR number: numbers»«number»«ENDFOR»

Another option is to use «numbers.join()»

另一种选择是使用«numbers.join()»

#2


The for loop construction

for循环结构

«FOR number: numbers»
    «number»
«ENDFOR»

has been mainly created to generates values on many lines. If you need to concatenate values on a single line, join() is a better option:

主要是为了在许多行上生成值而创建的。如果需要在一行上连接值,join()是更好的选择:

«numbers.join»

Shorter, cleaner, more clear. And you can also give a separator parameter

更短,更清洁,更清晰。您还可以提供分隔符参数

«numbers.join(", ")»