简体   繁体   English

可选语句之间的逗号

[英]Comma between optional statements

I am trying to generate code with stringtemplate4, and I have a line like this:我正在尝试使用 stringtemplate4 生成代码,并且我有这样的一行:

"<if(A)>\"A\":\"<A>\"<endif>, <if(B)>\"B\":\"<B>\"<endif>, <if(C)>\"C\":\"<C>\"<endif>"

so A, B and C are optional parameters that if they are not set, I don't want the whole statement to be in the output string.所以 A、B 和 C 是可选参数,如果没有设置,我不希望整个语句都在 output 字符串中。 That part is working fine but the comma after the statement is my problem, I don't want the comma to be there as well.那部分工作正常,但语句后的逗号是我的问题,我不希望逗号也在那里。 I can have the comma inside the string (like "," but then I might end up with an extra comma at the end. I think one way is to do it like a list but I don't know how to define that. this is not working:我可以在字符串中使用逗号(例如“,”,但最后可能会在末尾添加一个额外的逗号。我认为一种方法是像列表一样进行操作,但我不知道如何定义它。这个不管用:

"<[{<if(A)>\"A\":\"<A>\"<endif>,<if(B)>\"B\":\"<B>\"<endif>}]; separator=\",\">"

Any ideas?有任何想法吗? thanks.谢谢。

Not sure if I understand your question correctly, but can't just move the comma in the if?不确定我是否正确理解了您的问题,但不能只在 if 中移动逗号?

<if(A)>\"A\":\"<A>\", <endif><if(B)>\"B\":\"<B>\", <endif><if(C)>\"C\":\"<C>\"<endif>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM