How do I prevent the extra separator?

88 Views Asked by At

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

0

There are 0 best solutions below