List separators only between list elements

lukacs.akos posted this 17 August 2022


I have a list of people (IEnumerable of .NET objects, each with a FullName property), and I need an output an inline list of them that has a coma and a space between each name. For example "John Smith, Joe Smith". Pretty much what String.Join(", ", names) would do. If I put the name + coma + space in the "List" in the word template, I will almost get what I need, but it will have a trailing space+coma. Is there a way to achieve this in word? Or should be precomputed with String.Join in the data source?

Saw you mentioned XPath for a similar questions: Could you give an example?

Btw, do you have examples other than these? Evaluationg multiple solutions right now, and while I don't like Aspose's approach, they do have a lot of examples.

10 Posts
10 Points
Order By: Standard | Newest | Votes
jles posted this 19 August 2022

Hi Lucas,

I suggest that you first decide on the kind of a Data Source you are going to use. If you are going to stay with .NET Object based Data Sources, then you will need to create a calculated property that uses string.Join to concatenate strings, or the ElementInitialize to provide the same value on the fly:

Only if you decide to use XML based Data Sources you will be able to produce various values by writing XPath expression. In your case, you will be able to use the string-join XPath function.

-- Jure

154 Posts
294 Points

Our 225450 members have posted 342 times in 101 discussions