使用 != 的字符串比较返回真,即使两个字符串相同
string comparison using != is returning true even both strings are the same
我的 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.q123<br><br></p><p>It will exclude Win Server 2012. </p><p>Check attached spreadsheet in draft for list of servers and check the POF </p><p>Licenses:</p><p>Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. <br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require 6 x (16 cores licenses x 3 hosts) ---> 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  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:</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.q123<br><br></p><p>It will exclude Win Server 2012. </p><p>Check attached spreadsheet in draft for list of servers and check the POF </p><p>Licenses:</p><p>Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. <br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require 6 x (16 cores licenses x 3 hosts) ---> 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  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:</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.q123It will exclude Win Server 2012. Check attached spreadsheet in draft for list of servers and check the POF Licenses:Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. There are also 2 existing VMs running on Win Server 2012.This will require 6 x (16 cores licenses x 3 hosts) ---> 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  Win Server Standard16 cores licensesThe VM's running on Cloud will be licensed through monthly hosting costsCost Summary:Licenses - £12,612.60Engineer Resources - £7,880.00
但上面的字符串比较将 return 为真,尽管 2 个字符串是相同的。所以有人可以建议吗?
字符串不一样。 ----
这个词在第一个字符串中缺失,但在第二个字符串中出现(我按照 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
周围存在差异,因为那里似乎有非打印字符。
我的 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.q123<br><br></p><p>It will exclude Win Server 2012. </p><p>Check attached spreadsheet in draft for list of servers and check the POF </p><p>Licenses:</p><p>Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. <br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require 6 x (16 cores licenses x 3 hosts) ---> 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  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:</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.q123<br><br></p><p>It will exclude Win Server 2012. </p><p>Check attached spreadsheet in draft for list of servers and check the POF </p><p>Licenses:</p><p>Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. <br></p><p>There are also 2 existing VMs running on Win Server 2012.<br></p><p>This will require 6 x (16 cores licenses x 3 hosts) ---> 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  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:</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.q123It will exclude Win Server 2012. Check attached spreadsheet in draft for list of servers and check the POF Licenses:Tere will  be a total of 9 Server VMs upgraded on-premises that require Win Server Licenses. There are also 2 existing VMs running on Win Server 2012.This will require 6 x (16 cores licenses x 3 hosts) ---> 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  Win Server Standard16 cores licensesThe VM's running on Cloud will be licensed through monthly hosting costsCost Summary:Licenses - £12,612.60Engineer Resources - £7,880.00
但上面的字符串比较将 return 为真,尽管 2 个字符串是相同的。所以有人可以建议吗?
字符串不一样。 ----
这个词在第一个字符串中缺失,但在第二个字符串中出现(我按照 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
周围存在差异,因为那里似乎有非打印字符。