Comparing strings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennieku

    #1

    Comparing strings

    Does anybody have an idea how to compare two strings?
    What I want to know is the percentage of the differences between the strings

    Thx,
    Dennieku


  • Jon Skeet

    #2
    Re: Comparing strings

    Dennieku <dennieku@hotma il.com> wrote:[color=blue]
    > Does anybody have an idea how to compare two strings?
    > What I want to know is the percentage of the differences
    > between the strings[/color]

    Could you define exactly what you mean by "percentage of the
    differences"? If you can define it *exactly*, that will probably
    suggest a way of calculating it simply.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Robert Jacobson

      #3
      Re: Comparing strings

      I think what you're looking for (basically) is the Levenshtein edit-distance
      algorithm. This algorithm takes two strings as an input. It then counts
      the number of corrections (insertions, deletions or substitution of
      individual characters) that are necessary to make the strings the same.

      For example, with the inputs "Hello World" and "Hllo Woorld," it will return
      "2" since there are two corrections necessary: insert an "e" in the first
      word, and delete an "o" in the second word.

      This isn't built into the .Net framework, so you'll have to build your own.
      Try a Google search on "edit distance algorithm." There's an explanation of
      the algorithm here, with some VB6 code:





      "Dennieku" <dennieku@hotma il.com> wrote in message
      news:K375b.2265 5$Xh6.6917610@a msnews02.chello .com...[color=blue]
      > Does anybody have an idea how to compare two strings?
      > What I want to know is the percentage of the differences between the[/color]
      strings[color=blue]
      >
      > Thx,
      > Dennieku
      >
      >[/color]


      Comment

      • Chad Myers

        #4
        Re: Comparing strings

        "Jon Skeet" <skeet@pobox.co m> wrote in message
        news:MPG.19bf11 f69199f67f98a47 f@news.microsof t.com...[color=blue]
        > Dennieku <dennieku@hotma il.com> wrote:[color=green]
        > > Does anybody have an idea how to compare two strings?
        > > What I want to know is the percentage of the differences
        > > between the strings[/color]
        >
        > Could you define exactly what you mean by "percentage of the
        > differences"? If you can define it *exactly*, that will probably
        > suggest a way of calculating it simply.[/color]

        I think he means something like DIFFERENCE or
        SOUNDEX in SQL Server.

        Unfortunately there's nothing like this built into
        ..NET and it's not a simple algorithm, but I'm sure
        you could probably find some examples on some
        academic pages. I think it has something to do
        with phonetic analysis of the words and then
        comparing the likeness of the placement of the
        various phonetic parts relative to the other
        string. MSR might have something like this
        already, they are always suprising me with
        new projects.

        -c


        Comment

        • Jon Skeet

          #5
          Re: Comparing strings

          Robert Jacobson <rjacobson_at_o ddpost_com@nosp am.com> wrote:[color=blue]
          > I just noticed your cross-post to .dotnet.languag es.csharp -- the VB example
          > probably isn't what you're looking for. <g> That link also has examples in
          > Java and C++ that would be easy to translate to C#.[/color]

          In particular, I'd be more than happy to translate it from Java to C#,
          if this is indeed the algorithm required.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          • Jon Davis

            #6
            Re: Comparing strings

            I did a search .. you might find something useful in here...

            .NET Technologie, C#, csharp, ASP, ASP.NET, Microsoft, SSW, XML, web service, ADO, ADO.NET, Buch, book


            Jon


            "Chad Myers" <cmyers@N0.SP.A M.austin.rr.com > wrote in message
            news:utDEhWZcDH A.748@TK2MSFTNG P10.phx.gbl...[color=blue]
            > "Jon Skeet" <skeet@pobox.co m> wrote in message
            > news:MPG.19bf11 f69199f67f98a47 f@news.microsof t.com...[color=green]
            > > Dennieku <dennieku@hotma il.com> wrote:[color=darkred]
            > > > Does anybody have an idea how to compare two strings?
            > > > What I want to know is the percentage of the differences
            > > > between the strings[/color]
            > >
            > > Could you define exactly what you mean by "percentage of the
            > > differences"? If you can define it *exactly*, that will probably
            > > suggest a way of calculating it simply.[/color]
            >
            > I think he means something like DIFFERENCE or
            > SOUNDEX in SQL Server.
            >
            > Unfortunately there's nothing like this built into
            > .NET and it's not a simple algorithm, but I'm sure
            > you could probably find some examples on some
            > academic pages. I think it has something to do
            > with phonetic analysis of the words and then
            > comparing the likeness of the placement of the
            > various phonetic parts relative to the other
            > string. MSR might have something like this
            > already, they are always suprising me with
            > new projects.
            >
            > -c
            >
            >[/color]


            Comment

            Working...