I have two strings one with a double-byte value and the other is a single byte-one. The string comparison result returns false, how do I get them to compare correctly after ignoring the single-byte/double-byte difference?
string s1 = "smatsumoto11"
string s2 = "smatsumoto11"
In the same scenario, if you have a nvarchar column in SQL server which contains the value smatsumoto11
, a query to fetch the data with the where condition having the string smatsumoto11
will return the same row. I need similar semantics with C# string comparison.
I have tried a few options mentioned on MSDN but they don't seem to work.
Any ideas?
Your s1
contains so-called "fullwidth" characters, so you can use string.Compare
and tell it to ignore character width:
string.Compare(s1, s2, CultureInfo.CurrentCulture, CompareOptions.IgnoreWidth);
(Of course, specify a different CultureInfo
if necessary.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With