Stupid SharePoint Delimiters

I don’t like SharePoint delimiters. They make me all sorts of mad. You really get into them when working with custom field types such as multi selection bound fields. They parse out as “;#”. While that is all good for storage in SharePoint, sometimes programming against the field to pool values becomes a pain in the ass when writing WebParts or working on an arbitrary business application.

I needed a quick method to basically split on these this morning, so I threw this clunker together, which works fine. All it does is take the string parameter being passed in and use IndexOf against “;#” in order to return the first instance of the delimiter to get a starting point for the stripping. Once you have a the indexable numeric available to loop against, you can make two new strings that do the remove and replace functions, and then do all the returning.

public static string[] RemoveAndReplaceFieldValue(string strFieldValue)
if (strFieldValue == null)
throw new ArgumentNullException(“strFieldValue”);

int l_intIndex = strFieldValue.IndexOf(“;#”);

if (l_intIndex > -1)
string l_strRemove = strFieldValue.Remove(0, l_intIndex + 2);
string l_strReplace = strFieldValue.Replace(“;#” + l_strRemove, “”);
if (l_strRemove != null && l_strReplace != null)
return new string[] {l_strRemove, l_strReplace};

return new string[] { strFieldValue };

Probably not ideal, however it sure is functional.