如何在字符串之间找到等效(不相等)值?
//Equivalent Values
string A = "Beneficiation Return";
string B = "Return Beneficiation";
string C = "Beneficiation From Return";
string D = "Return From Beneficiation";
如果我使用
if(A == B)//Equal
它只会比较Equal字符串,它们是等价但不相等的,有没有办法验证等价?
等价可以是:混洗的单词,有或没有链接单词(Just 五:For,To,In,From,At。)或被洗牌并连接单词
代码会导致:
("Beneficiation Return" == "Return Beneficiation")True
("Beneficiation From Return" == "Return Beneficiation")True
("Return Beneficiation" == "Return From Beneficiation")True
答案 0 :(得分:0)
您可以创建一个辅助函数:equivalentStrings同时接受A和B.在该函数中,您可以执行以下操作:
答案 1 :(得分:0)
我认为这就是你要找的......
string a = "Beneficiation Return";
string b = "Return Beneficiation";
string c = "Beneficiation From Return";
string d = "Return From Beneficiation";
bool isSame = !a.Except(b).Any() && !b.Except(a).Any();
bool isSame
将返回true
,因为字符串a
& b
包含相同的字符。
将a
与c
进行比较,它将返回false