Question

I have a method in a url rewriting module that looks like this

public bool Match(Uri url)
  {
      string x = url.PathAndQuery.ToLowerInvariant();
      string y = RuleData.ToLowerInvariant();

   return x.Contains(y);
  }

However, it is not returning true for the following values:

x = "/xx09-02-09xx"; y = "09-02-09";

but if I write a unit test with the raw strings, like below, it does return true

[Test]
        public void Contains()
        {
            string x = "/xx09-02-09xx";
            string y = "09-02-09";
            Assert.IsTrue(x.Contains(y)); // this returns true
        }

What could be the difference? The encoding? The culture? Have tried removing the ToLowerInvarient(), but that makes no difference

have tried all the following in the Match method

bool contains = x.Contains(y);
bool contains1 = x.IndexOf(y) != -1;
bool contains2 = x.IndexOf(y, StringComparison.OrdinalIgnoreCase) != -1;
bool contains3 = x.IndexOf(y, StringComparison.InvariantCultureIgnoreCase) != -1;
bool contains4 = x.IndexOf(y, StringComparison.CurrentCultureIgnoreCase) != -1;

but none return true for those values, when run in the rewrite module. But they do in the unit test. So something about the strings is clearly different

any ideas?

Was it helpful?

Solution

Have you verified that the hyphens in the two strings are in fact the same characters? I would examine the character codes for them in the debugger to rule out any tricks that the character set may play.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top