Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > String comparisions

Reply
Thread Tools

String comparisions

 
 
Talib Hussain
Guest
Posts: n/a
 
      02-12-2009
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-forum.com/.

 
Reply With Quote
 
 
 
 
Dylan Evans
Guest
Posts: n/a
 
      02-12-2009
[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 <(E-Mail Removed)> 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-forum.com/.
>
>



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

 
Reply With Quote
 
 
 
 
Giampiero Zanchi
Guest
Posts: n/a
 
      02-12-2009
just for that instance:
p (strTwo.split - strOne.split).join

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

 
Reply With Quote
 
Alex Katebi
Guest
Posts: n/a
 
      02-12-2009
[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 <(E-Mail Removed)> 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-forum.com/.
>
>


 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      02-12-2009
2009/2/12 Talib Hussain <(E-Mail Removed)>:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer comparisions of same type T Ryi C Programming 4 03-24-2010 06:43 PM
String comparisions and counting Stuart Clarke Ruby 7 11-05-2008 02:47 PM
parser performance comparisions Eric Mahurin Ruby 9 11-06-2005 12:55 AM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM
Synthesis Tool Device Support Comparisions? td VHDL 0 09-13-2003 04:18 PM



Advertisments