且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在VB.NET中的字符串2字节和字符串1字节之间进行比较

更新时间:2022-11-01 20:08:20

(如果我认识您),请使用String.Replace方法从str1中删除不需要的空格(或其他内容).
(if I got you) Use String.Replace method to remove unwanted blanks (or whatever) from str1.


亲爱的朋友,

这将做到:-

Dear Friend,

This will do:-

string.Compare(s1, s2, CultureInfo.CurrentCulture, CompareOptions.IgnoreWidth)



请参考此链接以获取更多详细信息:-

http://***.com/questions/4142394/double-byte-string- comparison-in-c-sharp [ ^ ]

谢谢



Please refer this link for more details:-

http://***.com/questions/4142394/double-byte-string-comparison-in-c-sharp[^]

Thanks


我将开始阅读此MSDN文章并查看示例.

MSDN String.CompareTo [ 备注

CompareTo方法主要设计用于排序或按字母顺序排列的操作.当方法调用的主要目的是确定两个字符串是否等效时,不应使用它.要确定两个字符串是否相等,请调用Equals方法.
"

因此,如果您在比较实际值之后,请使用等于 [ ^ ]
I would start having a read of this MSDN article and looking at the examples.

MSDN String.CompareTo[^]

this shows that the ordinal position of the two string start in the same place

this is taken from the article

"
Remarks

The CompareTo method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the Equals method.
"

So if you are after comparing the actual values look at using the Equals[^]