Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quickest way to comma separate a Tridion multivalue field

What would be the quickest way to have a multivalue Tridion text field split into a comma separated string? In my case I am using C#, but I guess any other examples are welcome as well. This is the ugly and long way it seems:

var multiTextField = fields["multiTextField"] as TextField;
string multiCommaField = String.Empty;

for (int i = 0; i < multiTextField.Values.Count; i++)
{
    multiCommaField += multiTextField.Values[i].ToString() + ",";
}

Edit: I am using .NET 3.5 and Tridion 2009 SP1

like image 899
Hendrik Beenker Avatar asked May 15 '12 12:05

Hendrik Beenker


1 Answers

You haven't specified your version of Tridion or .Net in your question, but there are a few different techniques you could use to get comma separated values from the textfield.

If you're using .Net 4, I believe you could just do:

string.Join(",", multiTextField.Values);

as long as multiTextField.Values implements IList.

If you're using .Net 3.5 or earlier, I believe that the string.Join() function requires an array rather than IList.

There was a pretty good discussion regarding the options here String Join on a List (.Net 4)
or here Trying to string.Join an IList (.Net 4)
or here Creating a comma separated list from IList (.Net 3.5)

like image 116
Mike Percival Avatar answered Sep 28 '22 11:09

Mike Percival