String Comparision

  • Thread starter Thread starter forlist2001
  • Start date Start date
F

forlist2001

Hello there,

How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ

Thanks
KB
 
Thanks but when i do

string a = "Z";
a.CompareTo("BA");

system tells me that Z is greater than BA. :(
 
Oh, sorry, I misread your question. You must implement the comparison by
yourself in this case.
 
Thanks Guys for your help...

I have implemented my own comparer and it works...
:)
Code is in vb in c# forum sorry

Dim comp As New MyStringComparer
myAL.Sort(comp)

and my last value is in myAl.item(myAL.count -1)

Public Class MyStringComparer
Implements IComparer

Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements IComparer.Compare
Dim s1 As String = CStr(x)
Dim s2 As String = CStr(y)
If s1.Length < s2.Length Then
Return -1
ElseIf s1.Length = s2.Length Then
Return String.Compare(s1, s2)
Else
Return 1
End If
End Function
End Class
 
Kb said:
Thanks Guys for your help...

I have implemented my own comparer and it works...
:)
Code is in vb in c# forum sorry

Dim comp As New MyStringComparer
myAL.Sort(comp)

and my last value is in myAl.item(myAL.count -1)

Public Class MyStringComparer
Implements IComparer

Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements IComparer.Compare
Dim s1 As String = CStr(x)
Dim s2 As String = CStr(y)
If s1.Length < s2.Length Then
Return -1
ElseIf s1.Length = s2.Length Then
Return String.Compare(s1, s2)
Else
Return 1
End If
End Function
End Class

Make sure you Trim and UpperCase the strings also.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top