String comparisions


#1

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.


#2

strTwo.split(strOne)[1].lstrip

But that’s very specific.


#3

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

Giampiero


#4

Look into the ruby full-text search.


#5

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