字符串比较
字符串是由N个“***|”组成
例如:
A:“***|***|***|”
B:“***|ABC|***|”
如何判断字符串A和字符串B除红字以外部分相等?
PS:字符串是由N个“***|”组成,ABC(只是例子,不是真的ABC)出现的位置不定 string
[解决办法]
吧中间替换成空,然后比较
[解决办法]
字符串是由N个“***
[解决办法]
”组成,ABC(只是例子,不是真的ABC)出现的位置不定
截成数组 对比吧,估计有点慢
[解决办法]
up++
对于写代码来讲,楼上版主的方法最方便
[解决办法]
用字符串的Replace函,可解你的。
例:
string string1, string2, string3, string4;
string1 = "hello world 123";
string2 = "hello china 456";
string3 = "world";
string4 = "china";
if (string1.Replace(string3, "") == string2.Replace(string4, "")){
}
else{
}
[解决办法]
if (a.Where(x => x == '*').Count() == b.Where(x => x == '*').Count())
...
[解决办法]
string str1 = "aaa
[解决办法]
bbb
[解决办法]
ccc
[解决办法]
";
string str2 = "aaa
[解决办法]
asd
[解决办法]
ccc
[解决办法]
";
string[] t1 = str1.Split('
[解决办法]
');
string[] t2 = str2.Split('
[解决办法]
');
str1 = str1.Replace(t1[1],"");
str2 = str2.Replace(t2[1],"");
if (str1 == str2)
{
Console.WriteLine("True");
}
else
{
Console.WriteLine("False");
}