In Freemarker how do I insert the right number of spaces to place text in a specified column?

StackOverflow https://stackoverflow.com/questions/21590512

  •  07-10-2022
  •  | 
  •  

문제

I'm doing some simple C code generation using Freemarker. I am generating a line like the following:

#define MY_CONSTANT                   (0)

From a template of the form:

#define ${name}                   (${value})

I am generating a bunch of these and I want them to come out like this

#define MY_CONSTANT                   (0)
#define MY_NEW_CONSTANT               (42)
#define MY_OTHER_CONSTANT             (101)

With the values all column aligned. Is there an easy way to do this? Do I need to write a directive for it?

Thanks in advance.

도움이 되었습니까?

해결책

You can use the right_pad builtin.

#define ${name?right_pad(30)} (${value})

See the doc here.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top