简体   繁体   中英

Comma between optional statements

I am trying to generate code with stringtemplate4, and I have a line like this:

"<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. 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(A)>\"A\":\"<A>\", <endif><if(B)>\"B\":\"<B>\", <endif><if(C)>\"C\":\"<C>\"<endif>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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