For example, there are two strings like this:
Copy the codeThe code is as follows:
var a = "a-b=c12";
var b = "a.b___c12";
Well apparently no matter which conventional method you use, their comparison results are certainly not 0, because they vary in lengths, even if the lengths are equal due to the symbols between characters they cannot be equal.
How to ignore symbols in string comparisons? In fact, the enumeration option can meet this requirement. Use CompareInfo in CultureInfo, and then use CompareInfo's Compare method to compare two strings (here you can specify the CompareOptions enumeration).
Code:
Copy the codeThe code is as follows:
var a = "a-bc=12";
var b = "a.b___c12";
((a, b));
//Use InvariantCulture
((a, b, ));
//Current CultureInfo
((a, b, ));
Output:
Copy the codeThe code is as follows:
1
0
0
The method used later returns 0.