String Comparision

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • forlist2001@yahoo.com

    String Comparision

    Hello there,

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

    Thanks
    KB

  • Lebesgue

    #2
    Re: String Comparision

    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.

    <forlist2001@ya hoo.comwrote in message
    news:1158934041 .031753.233990@ d34g2000cwd.goo glegroups.com.. .
    Hello there,
    >
    How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ
    >
    Thanks
    KB
    >

    Comment

    • Kb

      #3
      Re: String Comparision

      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.
      >
      <forlist2001@ya hoo.comwrote in message
      news:1158934041 .031753.233990@ d34g2000cwd.goo glegroups.com.. .
      >Hello there,
      >>
      >How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ
      >>
      >Thanks
      >KB
      >>
      >
      >

      Comment

      • Lebesgue

        #4
        Re: String Comparision

        Oh, sorry, I misread your question. You must implement the comparison by
        yourself in this case.

        "Kb" <forlist2001@ya hoo.comwrote in message
        news:eiyo8Nl3GH A.4764@TK2MSFTN GP05.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.
        >>
        ><forlist2001@y ahoo.comwrote in message
        >news:115893404 1.031753.233990 @d34g2000cwd.go oglegroups.com. ..
        >>Hello there,
        >>>
        >>How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ
        >>>
        >>Thanks
        >>KB
        >>>
        >>
        >>

        Comment

        • Kb

          #5
          Re: String Comparision

          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 MyStringCompare r
          myAL.Sort(comp)

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

          Public Class MyStringCompare r
          Implements IComparer

          Function Compare(ByVal x As Object, ByVal y As Object) As Integer
          Implements IComparer.Compa re
          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


          forlist2001@yah oo.com wrote:
          Hello there,
          >
          How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ
          >
          Thanks
          KB
          >

          Comment

          • PS

            #6
            Re: String Comparision


            "Kb" <forlist2001@ya hoo.comwrote in message
            news:upm1Izm3GH A.1268@TK2MSFTN GP02.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 MyStringCompare r
            myAL.Sort(comp)
            >
            and my last value is in myAl.item(myAL. count -1)
            >
            Public Class MyStringCompare r
            Implements IComparer
            >
            Function Compare(ByVal x As Object, ByVal y As Object) As Integer
            Implements IComparer.Compa re
            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.
            >
            >
            forlist2001@yah oo.com wrote:
            >Hello there,
            >>
            >How do i compare string such that A < B<... <Y<Z<BA<BB... <CA... <ZZ
            >>
            >Thanks
            >KB
            >>

            Comment

            Working...