Multiple Lookup field , how to return better deliminators using object model?
-
16-10-2019 - |
Question
I have a multiple lookup field, and when I do this:
string myValue = oItem["MyLookupField"];
I get this string back:
[id];#[displayText];#[id];#[displayText]
or a real example:
"5;#C3;#15;#P3"
as you can see not the most logical string to split. Surely there must be a better way to get a splitable string back from sharepoint for a lookup field.
I would expect something like:
"5;C3|15;P3" (for example)
Anyone know how to get a better string back for a lookup field?
Solution
Instead of parsing them manually, try using the SPFieldLookupValue class instead:
or the SPFieldMultiChoiceValue class:
OTHER TIPS
The delimiter cannot be changed and is found in the SPFieldMultiChoiceValue.Delimiter property.
you can write own function like this
var Result = Regex.Split(data, ";#", RegexOptions.ExplicitCapture) .ToList().aggregate((x,y)=>x+";"+y+"|");
This solve your problem