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.
Talib H. (Guest)
on 2009-02-12 13: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 H.
Dylan E. (Guest)
on 2009-02-12 13:41
(Received via mailing list)
strTwo.split(strOne)[1].lstrip

But that's very specific.
Giampiero Z. (Guest)
on 2009-02-12 13:44
just for that instance:
p (strTwo.split - strOne.split).join

Giampiero
Alex K. (Guest)
on 2009-02-12 14:24
(Received via mailing list)
Look into the ruby full-text search.
Robert K. (Guest)
on 2009-02-12 15:16
(Received via mailing list)
2009/2/12 Talib H. <removed_email_address@domain.invalid>:

> 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.