2

I have the following xmlnode (string) whose value would be of few given type i.e:

"Ansi_nulls","Encrypted","Quoted_identifer" etc.

I want to test the xmlnode using xmlNode.Contains ("xxx","yyy") ..

What is the correct syntax ?

5 Answers 5

3

If you are testing the full (complete) value of the node, you can do it by reversing the call; check that a list of known values contains your current node value:

new[]{"Ansi_nulls","Encrypted","Quoted_identifer", ...}.Contains(xmlNode);
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this would only allow full-matches, not equivalent to the OP xmlNode.Contains ("xxx","yyy") which would substrings too
3

I would create an extension method using sehes solution:

    public static bool Contains(this string source, params string[] values)
    {
        return values.Any(value => source.Contains(value));
    }

That way you can call:

        xmlNode.Contains("string", "something else");

Comments

2

Contains takes a string to test for.

One way to solve your problem would be to use a simple regular expression

using System.Text.RegularExpressions;

if (Regex.IsMatch(nodevalue, "(Ansi_nulls|Encrypted|Quoted_identifer)")...

Comments

2
if (new[] {"xxx","yyy"}.Any(n => xmlNode.Contains(n)))

Comments

0

A simple if statement will work:

if (xmlNode.Contains("xxx") && xmlNode.Contains("yyy"))
{
// your work
}

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.