0

Given the code ST4 C# code below, how do I prevent the trailing separator (',') from appearing in my output? The trailing separator won't appear if there aren't items to skip after the first item is output (e.g. if the third item in the list isn't present). So, clearly the problem has to do with skipping items, but it doesn't have a problem skipping the first item (e.g. no leading separator before outputting the second item).

2 is even,

static void Main (string [] args)
        {
        List <Item> items = new List <Item> () { new Item ("1", false), new Item ("2", true), new Item ("3",false)};
        string      string_template_group =
@"
even_params (parameters) ::=
<<
<parameters:{p|<if (p.is_even)><p.value> is even<endif>}; separator = "", "">
>>
";
        TemplateGroup   group = new TemplateGroupString (string_template_group);

        Template even_params = group.GetInstanceOf ("even_params");
        even_params.Add ("parameters", items);
        Console.WriteLine (even_params.Render ());
        }   // End Main

    }   // End class Program

class Item
    {
    public string   value   { get; set; }
    public bool     is_even { get; set; }

    public Item (string V, bool E)
        {
        value = V;
        is_even = E;
        }

    }   // End class Item

Changing the separator to "sep" (as requested by @Har) provides the expected output:

2 is evensep

Brian
  • 305
  • 1
  • 11
  • What do you get if you change the separator into something else such as separator="sep" ? – Har Dec 07 '19 at 18:31
  • 1
    @Har It outputs "2 is evensep". It seems like it is outputting the separator immediately after the text is output, rather than waiting to know if there will be any more items output. Note, that it did not write "sep2 is evensep", so it knows not to output the separator for items skipped at the beginning of the list, but once it outputs an item, it will output a separator for every item remaining in the list, even if the item is not output. Please fix! – Brian Dec 10 '19 at 03:03

0 Answers0