1

I have 2 list items that contains a title field with following string value

Item 1 Title : apple,blackgreen

Item 2 Title : apple,black

I want to query the list item if comma separated word in the title exact match "black", currently equal operator in CAML query does not give me anything, contains give me both results, but I want only second list item.

2 Answers 2

2

I don't think this is currently possible since it's a comma seperated value. All filtering options are void since searching on exact word contains either 0 or 2 since both contain the word black.

Unless I am mistaken CAML Query does not Support removing a character in this case the comma and then search for exact word. if it was space seperated instead there would probeply be possibilities however as it is right there is not.

Option 1

Filter on contains the words:

  • ,black
  • ,black,

and exact match: black

Option 2

Though less than effecient you could search for annything containing black. And then split on the comma and then filter on exact word black.

This would reduce your Initial call and then you could filter properly with a smaller data object/Array.

Hope this helps

1

Using Linq query, you can get result what exactly you want.

var reg = new Regex("\\\bblack\\\b", RegexOptions.IgnoreCase);

var result = from item in lst.Items.Cast<SPListItem>()
             where reg.IsMatch(item["Title"].ToString())
             select item;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.