
Signature
Regards,
Al Christoph
Senior Consultant and Proprietor
Three Bears Software, LLC
just right software @ just right prices @3bears.biz
Use the CompareTo method on strings. Strings in J# are treated as true
objects, so the equality operator will compile, but provide reference
equality, not value equality.

Signature
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
> I am really puzzled in one piece of code the obvious worked and in another it
> didn't
[quoted text clipped - 21 lines]
> Crystal Repots. UGH!!!!! BTW one of my mottos is that "If Bill Gates had a
> hand in it, you shouldn't need a manual." (The other is "Bill Gates won.")
George Birbilis [MVP J#] [9880] - 13 Sep 2005 12:22 GMT
In the Java spec it's similar, never use == to compare strings, the
underlying objects will be compared for being the same object.
Sun Java VM happens to reuse string data (since strings are "immutable" [you
can't edit an existing string, but only make a new string or char array out
of it]), so that if you have two string fields holding the same text,
chances are they point to the same underlying "string" object. So sometimes
"==" will work in Sun Java VM, sometimes not (which can be quite tricky to
debug, but still saves some memory space esp. if you have quite big strings)
J# could do similarly, but still it doesn't solve your case, use ".equals"
method of a string class instance instead for comparison of two Java strings
(also the String class maybe has some static method to compare two given
strings)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
George Birbilis <birbilis@kagi.com>
Microsoft Most Valuable Professional
MVP J# for 2004, 2005
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ QuickTime (Delphi & ActiveX: VB, PowerPoint, .NET)
+ Plugs (InterProcess/Internet communication)
http://www.kagi.com/birbilis
+ Robotics
http://www.mech.upatras.gr/~robgroup
........................................................................
> Use the CompareTo method on strings. Strings in J# are treated as true
> objects, so the equality operator will compile, but provide reference
[quoted text clipped - 25 lines]
> > Crystal Repots. UGH!!!!! BTW one of my mottos is that "If Bill Gates had a
> > hand in it, you shouldn't need a manual." (The other is "Bill Gates won.")
Remember: J# is some variant of Java. And Java specs say that == test the
references, not the values.
You can fix this by using equals:
if (s.equals("")) { ... }
Note: as J# gives you access to both the Java framework (JDK) and the .NET
framework, you have the choice between:
s.equals("") // JDK equals
s.Equals("") // .NET equals
These 2 methods are equivalent but this is not the case of all string
methods. So be careful. For example:
s1.compareTo(s2) // JDK version: compares the unicode values (binary
comparison)
s1.CompareTo(s2) // .NET version: compares according to current locale's
collation rules
and also
s1.indexOf(start, end) // JDK version: 2nd arg is end index
s1.IndexOf(start, len) // .NET version: 2nd arg is len of substring
So, I suggest that you learn some basics about the JDK and Java (like the
fact that == compares references) so that you don't get too many bad
surprises.
Bruno.
>I am really puzzled in one piece of code the obvious worked and in another
>it
[quoted text clipped - 25 lines]
> Crystal Repots. UGH!!!!! BTW one of my mottos is that "If Bill Gates had a
> hand in it, you shouldn't need a manual." (The other is "Bill Gates won.")