I’d like to compare between two strings having html tags in different orders.
Example:
string str1="""<p><strong style="font-size: 36px; color: rgb(153, 51, 255);">Hello </strong><em><u>World</u></em></p>""";
string str2="""<p><strong style="color: rgb(153, 51, 255); font-size: 36px;">Hello </strong><em><u>World</u></em></p>""";
I care about the text as well as the style so I want the result of the comparison to be identical because it gives the same text with the same html result. However, a normal string comparison gives that the two strings are different.
how can I compare these two strings using c# not javascript.
2
Answers
to compare the 2 string you have to make few steps:
to do that you first need to add nuget package HtmlAgilityPack,
here is sample code
My approach is not using HtmlAgilityPack, but plain C# and is making use of:
System.Xml.Linq
. This solution can work for the simple cases that u need: