Сравнение строк с использованием! = возвращает истину, даже если обе строки одинаковы - PullRequest
0 голосов
/ 27 января 2020

У меня есть следующий код внутри моего asp. net приложения:

if (i["ProjectDescription"] != null && properties.ItemEventProperties.AfterProperties["ProjectDescription"] != null && (Regex.Replace(i["ProjectDescription"].ToString(), "<.*?>", String.Empty) != Regex.Replace(properties.ItemEventProperties.AfterProperties["ProjectDescription"].ToString(), "<.*?>", String.Empty)))
 {
    var g = Regex.Replace(i["ProjectDescription"].ToString(), "<.*?>", String.Empty);
    var gg = Regex.Replace(properties.ItemEventProperties.AfterProperties["ProjectDescription"].ToString(), "<.*?>", String.Empty);
}

теперь properties.ItemEventProperties.AfterProperties["ProjectDescription"] =

<div class=\"ExternalClassB4424BCE886A43C980835358CB67D0E8\"><p>This project will be to update Win Server 2008 or older server OS to Win Server 2016.q​123​​<br><br></p><p>It will exclude Win Server 2012.&#160;</p><p>Check attached spreadsheet in draft for list of servers and check the POF&#160;</p><p>Licenses&#58;</p><p>Tere will&#160; be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses.&#160;<br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require&#160;​6 x (16 cores licenses x 3 hosts) ---&gt; Total 18 x 16 cores Win Standard License​<br>already have 5 x 16 cores Win Standard licenses</p><p>We will need to quote and order for additional 13​ x&#160; Win Server Standard16 cores licenses​<br></p><p>The VM's running on Cloud will be licensed through monthly hosting costs</p><p><strong>Cost Summary&#58;​</strong><br>Licenses - £12,612.60<br>Engineer Resources - £7,880.00<br></p></div>

i["ProjectDescription"] =

<div class=\"ExternalClassB4424BCE886A43C980835358CB67D0E8\"><p>This project will be to update Win Server 2008 or older server OS to Win Server 2016.q​123<br><br></p><p>It will exclude Win Server 2012.&#160;</p><p>Check attached spreadsheet in draft for list of servers and check the POF&#160;</p><p>Licenses&#58;</p><p>Tere will&#160; be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses.&#160;<br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require&#160;​6 x (16 cores licenses x 3 hosts) ---&gt; Total 18 x 16 cores Win Standard License​<br>already have 5 x 16 cores Win Standard licenses</p><p>We will need to quote and order for additional 13​ x&#160; Win Server Standard16 cores licenses​<br></p><p>The VM's running on Cloud will be licensed through monthly hosting costs</p><p><strong>Cost Summary&#58;​</strong><br>Licenses - £12,612.60<br>Engineer Resources - £7,880.00<br></p></div>

также результат для Regex будет повторять следующее: -

This project will be to update Win Server 2008 or older server OS to Win Server 2016.q​123It will exclude Win Server 2012.&#160;Check attached spreadsheet in draft for list of servers and check the POF&#160;Licenses&#58;Tere will&#160; be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses.&#160;There are also 2 existing VMs running on Win Server 2012.This will require&#160;​6 x (16 cores licenses x 3 hosts) ---&gt; Total 18 x 16 cores Win Standard License​ already have 5 x 16 cores Win Standard licensesWe will need to quote and order for additional 13​ x&#160; Win Server Standard16 cores licenses​The VM's running on Cloud will be licensed through monthly hosting costsCost Summary&#58;​Licenses - £12,612.60Engineer Resources - £7,880.00

, но приведенное выше сравнение строк вернет true, хотя строка 2 одинакова. так может кто-нибудь посоветовать?

1 Ответ

3 голосов
/ 27 января 2020

Строки не совпадают. Слово ---- отсутствует в первой строке, но присутствует во второй (я удалил слово в соответствии с запросом OP, поскольку оно было действительным именем пользователя).

properties.ItemEventProperties.AfterProperties["ProjectDescription"]:

...Total 18 x 16 cores Win Standard License​<br>already have 5 x 16 cores Win Standard licenses</p>...

i["ProjectDescription"]:

...Total 18 x 16 cores Win Standard License​<br>----already have 5 x 16 cores Win Standard licenses</p>...

И как сказал MindSwipe в комментарии, существуют различия в 2016.q123<br><br></p><p>It, так как там, похоже, нет печатных символов.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...