how to find difference between two strings

Discussion in 'Ruby' started by Priyank Shah, Jul 30, 2010.

  1. Priyank Shah

    Priyank Shah Guest

    Hi,

    I have two strings, like
    @a = "hello"
    @b = "h123llo"

    so in that how can i print diffrence?

    i want difference like user know which diffrence on which character.

    Please let me know if any one know.

    Thanks in advance
    Priyank
    --
    Posted via http://www.ruby-forum.com/.
    Priyank Shah, Jul 30, 2010
    #1
    1. Advertising

  2. Peter Hickman, Jul 30, 2010
    #2
    1. Advertising

  3. Priyank Shah

    Josh Cheek Guest

    [Note: parts of this message were removed to make it a legal post.]

    On Fri, Jul 30, 2010 at 8:17 AM, Priyank Shah <>wrote:

    > Hi,
    >
    > I have two strings, like
    > @a = "hello"
    > @b = "h123llo"
    >
    > so in that how can i print diffrence?
    >
    > i want difference like user know which diffrence on which character.
    >
    > Please let me know if any one know.
    >
    > Thanks in advance
    > Priyank
    > --
    > Posted via http://www.ruby-forum.com/.
    >
    >

    "Difference" in this case does not seem very well defined.
    Josh Cheek, Jul 30, 2010
    #3
  4. Priyank Shah

    Intransition Guest

    On Jul 30, 9:17=A0am, Priyank Shah <> wrote:
    > Hi,
    >
    > I have two strings, like
    > @a =3D "hello"
    > @b =3D "h123llo"
    >
    > so in that how can i print diffrence?
    >
    > i want difference like user know which diffrence on which character.


    There is strmask (http://rubyworks.github.com/strmask/)

    Also the Levenshtein distance is String#edit_distance in Ruby Facets.
    Intransition, Jul 30, 2010
    #4

  5. >
    > i want difference like user know which diffrence on which character.
    >

    There's a "differ" gem which could be useful for you.

    Gavin
    Gavin Sinclair, Jul 30, 2010
    #5
  6. Priyank Shah

    Priyank Shah Guest

    Priyank Shah wrote:
    > Hi,
    >
    > I have two strings, like
    > @a = "hello"
    > @b = "h123llo"
    >
    > so in that how can i print diffrence?
    >
    > i want difference like user know which diffrence on which character.
    >
    > Please let me know if any one know.
    >
    > Thanks in advance
    > Priyank




    Thanks to you all but i want difference so i used

    http://codeidol.com/other/rubyckbk/Files-and-Directories/Comparing-Two-Files/

    And its working fine but i actully want exact difference.

    and it just shows me number of differences.

    So if you have any idea regarding this then please suggest.

    Thanks,
    Priyank Shah

    --
    Posted via http://www.ruby-forum.com/.
    Priyank Shah, Jul 31, 2010
    #6
  7. Priyank Shah

    Intransition Guest

    On Jul 31, 1:11=A0am, Priyank Shah <> wrote:
    > Priyank Shah wrote:
    > > Hi,

    >
    > > I have two strings, like
    > > @a =3D "hello"
    > > @b =3D "h123llo"

    >
    > > so in that how can i print diffrence?

    >
    > > i want difference like user know which diffrence on which character.

    >
    > > Please let me know if any one know.

    >
    > > Thanks in advance
    > > Priyank

    >
    > Thanks to you all but i want difference so i used
    >
    > http://codeidol.com/other/rubyckbk/Files-and-Directories/Comparing-Tw...
    >
    > And its working fine but i actully want exact difference.
    >
    > and it just shows me number of differences.
    >
    > So if you have any idea regarding this then please suggest.


    As in:

    @b.split(//) - @a.split(//)

    ?
    Intransition, Jul 31, 2010
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,032
  2. Replies:
    2
    Views:
    348
    Chris Smith
    May 5, 2006
  3. thebjorn
    Replies:
    23
    Views:
    1,525
    thebjorn
    Jul 29, 2006
  4. Prafull Soni
    Replies:
    1
    Views:
    663
    osmium
    Mar 7, 2005
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    733
    Malcolm
    Jun 24, 2006
Loading...

Share This Page