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)
-
-
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)
-
{
-
}
-
}
-
-
}
Probably not ideal, however it sure is functional.
Related posts:
- Getting GAC Path Using Reflection
- CMMi is Stupid, Agile is Better
- Stupid ISAPI filter! I hate unmanaged code!
- Getting a SharePoint Field Value In C#
- Determine If SharePoint List Column Exists In C#
1 Comment »
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 

Why not use one of the value types for the SPFieldControls (SPFieldLookupValue/SPFieldMultiChoiceValue)? They account for the delimiters, and allow you to get the values out with ease.
SPFieldLookupValue splv = new SPFieldLookupValue(strFieldValue);
string value = splv.LookupValue;
Comment by Rich Finn — November 2, 2007 @ 10:55 am