Why CommaDelimitedStringCollection Made Me Happy Today
Another thing that I stumbled on today that has made me all sorts of happy is the CommaDelimitedStringCollection class, which basically let's you take a bunch of string values and work with them in a comma delimited format (so I guess the class name is pretty intuitive
). I can't even explain how many times I have re-invented this wheel. So let's say that you have a ListBox control that contains a set of string type values, and you are adding the selected values to a list generic in something like an event handler, you would have this basically:
-
foreach (string l_strValue in l_oTbExample.SelectedItems)
-
{
-
m_gBoxGeneric.Add(l_strValue);
-
}
where the l_oTbExample is just a ListBox control. This isn't very earthshattering and I am just using that loop as an example. Now, let's say you want to output those selected values into a comma delimited format. The easiest way to do it is to just use the CommaDelimitedStringCollection class, which natively provides this functionality. It would look like this:
-
-
List<String>.Enumerator l_oEnumerator = m_gBoxGeneric.GetEnumerator();
-
try
-
{
-
while (l_oEnumerator.MoveNext())
-
{
-
string l_strBoxVal = l_oEnumerator.Current;
-
m_oDelimitedFormat .Add(l_strBoxVal);
-
}
-
}
-
finally
-
{
-
l_oEnumerator.Dispose();
-
}
Then you can just output the comma delimited values by doing a m_oDelimitedFormat.ToString() and you are done!
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL





















Articles & Research
SharePoint Architecture
Personal/Off-Topic
Latest Free SharePoint Software
SecureCenter For SharePoint
SharePoint Security Assurance Program™
Free Online SharePoint Security Tools
Online SharePoint Security Health Assessment
Article Or Research Filed Under 