[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

String comparisions

Talib Hussain

2/12/2009 11:21:00 AM

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
--
Posted via http://www.ruby-....

4 Answers

Dylan Evans

2/12/2009 11:40:00 AM

0

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

strTwo.split(strOne)[1].lstrip

But that's very specific.


On Thu, Feb 12, 2009 at 9:20 PM, Talib Hussain <talibhn@gmail.com> wrote:

> 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
> --
> Posted via http://www.ruby-....
>
>


--
The UNIX system has a command, nice ... in order to be nice to the other
users. Nobody ever uses it." - Andrew S. Tanenbaum

Giampiero Zanchi

2/12/2009 11:43:00 AM

0

just for that instance:
p (strTwo.split - strOne.split).join

Giampiero
--
Posted via http://www.ruby-....

Alex Katebi

2/12/2009 12:22:00 PM

0

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

Look into the ruby full-text search.

On Thu, Feb 12, 2009 at 6:20 AM, Talib Hussain <talibhn@gmail.com> wrote:

> 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
> --
> Posted via http://www.ruby-....
>
>

Robert Klemme

2/12/2009 1:14:00 PM

0

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

--
remember.guy do |as, often| as.you_can - without end