1

Is there a toupper or tolower or similar functions I can use to do a case-insensitive LINQ to XML query? If so, how do you revise the following line of code to do a case-insensitive query? Thanks.

User types search word into textbox and I do this in LINQ:

where d.Element("ProductName").Value.Contains(textBox1.Text)

2 Answers 2

4

It is very simple (and not correct)

where d.Element("ProductName").Value.Equals(
  textBox1.Text, StringComparison.InvariantCultureIgnoreCase) 

Ok, edited - more on MSDN:

where d.Element("ProductName").Value.IndexOf(
  textBox1.Text, StringComparison.InvariantCultureIgnoreCase) > 0
1
  • (S)he's not doing equal, rather contains
    – AD.Net
    Oct 20, 2011 at 19:18
2
where d.Element("ProductName").Value.ToLower().Contains(textBox1.Text.ToLower())

You probably should do some sort of null check though, just in case.

Your Answer

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

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