String Comparision

  • Thread starter Thread starter Kb
  • Start date Start date
K

Kb

Hello There,

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

Thanks
KB
 
Write a comparer for it as Z < BA == false in normal coding. You would need
to compare lengths first, then compare two of the same length as normal I
imagine.

HTH

Ciaran O'Donnell
 
Kb said:
Hello There,

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

It might be best to think of these as numbers but in base 36. Then the above
comparisons would be correct.

PS
 
In addition to the other comments, you might be able to PadLeft the shorter
string with max length of the two strings...

Something like:

Public Class SpecialComparer
Implements IComparer(Of String)

Public Function Compare(ByVal x As String, ByVal y As String) As
Integer Implements IComparer(Of String).Compare
Dim totalWidth As Integer = Math.Max(x.Length, y.Length)
Return String.Compare(x.PadLeft(totalWidth),
y.PadLeft(totalWidth))
End Function

End Class
 

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