如何在VB.NET中的字符串2字节和字符串1字节之间进行比较 [英] How to compare between a string 2 byte and a string 1 byte in VB.NET

查看:174
本文介绍了如何在VB.NET中的字符串2字节和字符串1字节之间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Friends

如何比较2个字符串1个字节和2个字节?
例如:我有2个字符串:str1(2 byte)="MBS"
str2(1字节)="MBS"

如何命令str1.CompareTo(str2)返回值0(2个字符串相同)?


非常感谢您!

Hi Friends

how to compare 2 string 1 byte and 2 byte?
Ex: I have 2 string : str1(2 byte)= "MBS"
str2(1 byte)= "MBS"

how to command str1.CompareTo(str2) return value 0 (2 string are the same)?


Thanh you very much!

推荐答案

(如果我认识您),请使用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://stackoverflow.com/questions/4142394/double-byte-string- comparison-in-c-sharp [ ^ ]

谢谢



Please refer this link for more details:-

http://stackoverflow.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[^]


这篇关于如何在VB.NET中的字符串2字节和字符串1字节之间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆