Gun Gun - 3 months ago 15x
HTML Question

c# Can't match Html Special characters

I have to match 2 urls, the first one comes from MySQL db and the second one comes from an Html page. If I compare both as string

var match = Regex.Match(href.Attributes["href"].Value, testString, RegexOptions.IgnoreCase);

match.Success = false.
Both strings are like
this : myUrl/rollcontainer-weiß
but the match.Success is still false.

I tried to add
to check both strings and I get :
for the first one and
for the second one.

How can I have a
match.Success = true
in this case ?


Try this function, for example.

static void Main(string[] args)
    bool test = Test("ß", "ß");


public static bool Test(string url1, string url2)
    Uri uri1 = new Uri(HttpUtility.HtmlDecode(url1)); 
    Uri uri2 = new Uri(HttpUtility.HtmlDecode(url2));

    var result = Uri.Compare(uri1, uri2,
        UriComponents.Host | UriComponents.PathAndQuery,
        UriFormat.Unescaped, StringComparison.OrdinalIgnoreCase);

    return result == 0;