Forum: Ruby String comparisions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
358a4fdb8939d8fc7ee6a439174c0446?d=identicon&s=25 Talib Hussain (talib)
on 2009-02-12 12:22
Experts,

I have a requirement of comparing string and getting the difference out

For Example :

strOne = "Hello, this is a test"
strTwo = "Hello, this is a test forum"

This should result that word "forum" is extra.

Any thoughts?

Regards,
Talib Hussain
42773b24e0c3fb506a8a875c058a9dd7?d=identicon&s=25 Dylan Evans (Guest)
on 2009-02-12 12:41
(Received via mailing list)
strTwo.split(strOne)[1].lstrip

But that's very specific.
64aa4b69fdd7127e6f3ee16ae065a620?d=identicon&s=25 Giampiero Zanchi (giampiz)
on 2009-02-12 12:44
just for that instance:
p (strTwo.split - strOne.split).join

Giampiero
B839a3a133b0ec4ece6af508c9c0d9a3?d=identicon&s=25 Alex Katebi (Guest)
on 2009-02-12 13:24
(Received via mailing list)
Look into the ruby full-text search.
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (Guest)
on 2009-02-12 14:16
(Received via mailing list)
2009/2/12 Talib Hussain <talibhn@gmail.com>:

> I have a requirement of comparing string and getting the difference out
>
> For Example :
>
> strOne = "Hello, this is a test"
> strTwo = "Hello, this is a test forum"
>
> This should result that word "forum" is extra.
>
> Any thoughts?

IMHO your question is by far not specific enough.  What kind of output
do you expect exactly?  Do you want all _words_ reported that are
missing or extra?  Do you have to have _substrings_ reported which are
missing or extra? Do you need _positional information_ with that?  If
so, which (word position, character position)?  Do you need human
readable output or do you want to automatically process it?  etc.

Cheers

robert
This topic is locked and can not be replied to.