Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Comparison: C# vs Java

Status
Not open for further replies.

Rewbs

Programmer
May 1, 2002
18
GB
Hi all,

Has anyone else noticed the differences in values returned by string comparison in C# and Java?

C#: Java*:

"1".CompareTo("2"): -1 -1
"b".CompareTo("a"): 1 1
"ant".CompareTo("art"): -1 -4
"(".CompareTo("a"): -1 -57
"!".CompareTo("_"): -1 -62

"a".CompareTo("A"): -1 32
"0".CompareTo("_"): 1 -47

*of course, in .compareTo is used in Java, not .CompareTo.

Notice how for the last two, even the sign is different, implying a different concept of lexicographical ordering!

I know Java uses Unicode values. What does C# use?
Is there a way to get the same values out of C#?

Cheers,
Robin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top