字符串比较问题 [英] string compare problem

查看:79
本文介绍了字符串比较问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比较两个字符串时,我得到了不同的结果

使用" =="和string.Compare()。

这两个字符串似乎具有相同的值1202002。在

快速监视,两者都有相同的长度7,我试图通过debug.writeline()打印出来。

但是==运算符结果为false,string.Compare()

结果为true。

有人帮助我!

I''ve got different result when comparing two strings
using "==" and string.Compare().
The two strings seems to have same value "1202002" in
the quick watch, and both have the same length 7 which I
have tried to print out by debug.writeline().
But the "==" operator results false, and string.Compare()
results true.
Somebody helps me!

推荐答案

David zhu写道:
David zhu wrote:
我在比较两个字符串时得到了不同的结果
使用" =="和string.Compare()。
两个字符串似乎具有相同的值1202002。在快速监视中,两者都具有相同的长度7,我试图通过debug.writeline()打印出来。
但是==运算符结果为false,string.Compare()
结果为true。
有人帮助我!
I''ve got different result when comparing two strings
using "==" and string.Compare().
The two strings seems to have same value "1202002" in
the quick watch, and both have the same length 7 which I
have tried to print out by debug.writeline().
But the "==" operator results false, and string.Compare()
results true.
Somebody helps me!




不同的字符集可以生成不同的结果。 ASCII,UTF-8,

Unicode。


你不应该使用==进行字符串比较 - 只使用字符串方法。


-

w 4



Different character sets can generate different results. ASCII, UTF-8,
Unicode.

You should never use == for string comparisons -- only the string methods.

--
w 4




" David zhu" < ZH *** @ handsome.com.cn>在留言中写道

news:27 ***************************** @ phx.gbl ...

"David zhu" <zh***@handsome.com.cn> wrote in message
news:27*****************************@phx.gbl...
比较两个字符串时,我得到了不同的结果
使用==和string.Compare()。
两个字符串似乎具有相同的值1202002。在快速监视中,两者都具有相同的长度7,我试图通过debug.writeline()打印出来。
但是==运算符结果为false,string.Compare()
结果为true。
有人帮助我!
I''ve got different result when comparing two strings
using "==" and string.Compare().
The two strings seems to have same value "1202002" in
the quick watch, and both have the same length 7 which I
have tried to print out by debug.writeline().
But the "==" operator results false, and string.Compare()
results true.
Somebody helps me!




字符串对象是对实际字符串的引用。因此,它们持有字符串的

地址。

如果使用==来比较String对象,则表示您正在比较地址,而不是

字符串的内容。

除非你创建了两个对同一个字符串的引用,否则s1 == s2永远不会是
为真。

使用String类中定义的方法。


-

Peter [MVP Visual Developer]

Jack of所有行业,无人掌握。



String objects are references to the actual strings. As such, they hold the
address of a string.
If you use == to compare String objects, you are comparing addresses, not
the contents of the strings.
Unless you''ve created two references to the same string, s1 == s2 will never
be true.
Use the methods defined in the String class.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.





" 802.16a"写道:


"802.16a" wrote:
David zhu写道:
David zhu wrote:
比较两个字符串时,我得到了不同的结果
使用== "和string.Compare()。
两个字符串似乎具有相同的值1202002。在快速监视中,两者都具有相同的长度7,我试图通过debug.writeline()打印出来。
但是==运算符结果为false,string.Compare()
结果为true。
有人帮助我!
I''ve got different result when comparing two strings
using "==" and string.Compare().
The two strings seems to have same value "1202002" in
the quick watch, and both have the same length 7 which I
have tried to print out by debug.writeline().
But the "==" operator results false, and string.Compare()
results true.
Somebody helps me!



不同的字符集可以生成不同的结果。 ASCII,UTF-8,
Unicode。

你不应该使用==进行字符串比较 - 只使用字符串方法。



Different character sets can generate different results. ASCII, UTF-8,
Unicode.

You should never use == for string comparisons -- only the string methods.




我不相信.net中的字符串包含任何编码信息。 .net中的字符串始终是unicode。



I don''t believe the string in .net holds any encoding information. a string in .net is always unicode.


这篇关于字符串比较问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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