By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,896 Members | 1,983 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,896 IT Pros & Developers. It's quick & easy.

String Comparision

P: n/a
Hello there,

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

Thanks
KB

Sep 22 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Use the CompareTo method of the string.

string a = "A";
a.CompareTo("B");

see http://msdn2.microsoft.com/en-us/lib...compareto.aspx
for details.

<fo*********@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
Hello there,

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

Thanks
KB

Sep 22 '06 #2

P: n/a
Kb
Thanks but when i do

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

system tells me that Z is greater than BA. :(

Lebesgue wrote:
Use the CompareTo method of the string.

string a = "A";
a.CompareTo("B");

see http://msdn2.microsoft.com/en-us/lib...compareto.aspx
for details.

<fo*********@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>Hello there,

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

Thanks
KB

Sep 22 '06 #3

P: n/a
Oh, sorry, I misread your question. You must implement the comparison by
yourself in this case.

"Kb" <fo*********@yahoo.comwrote in message
news:ei**************@TK2MSFTNGP05.phx.gbl...
Thanks but when i do

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

system tells me that Z is greater than BA. :(

Lebesgue wrote:
>Use the CompareTo method of the string.

string a = "A";
a.CompareTo("B");

see http://msdn2.microsoft.com/en-us/lib...compareto.aspx
for details.

<fo*********@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googleg roups.com...
>>Hello there,

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

Thanks
KB


Sep 22 '06 #4

P: n/a
Kb
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
fo*********@yahoo.com wrote:
Hello there,

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

Thanks
KB
Sep 22 '06 #5

P: n/a
PS

"Kb" <fo*********@yahoo.comwrote in message
news:up**************@TK2MSFTNGP02.phx.gbl...
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.
>

fo*********@yahoo.com wrote:
>Hello there,

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

Thanks
KB
Sep 24 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.