# How to compare 2 string object and display the differences

**URL:** <https://www.ruby-forum.com/t/how-to-compare-2-string-object-and-display-the-differences/166561>\
**Category:** Rails\
**Created:** [April 27, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/how-to-compare-2-string-object-and-display-the-differences/166561 "2009-04-27T13:01:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Geekyra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/a5b964/32.png) [@Geekyra](https://www.ruby-forum.com/u/Geekyra)\
**Post date:** [April 27, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/how-to-compare-2-string-object-and-display-the-differences/166561/1 "2009-04-27T13:01:19Z")

</div>

Hello, what is the best choice to compare 2 string/text in Ruby ? For  
example i have 2 model that each of it have a “content” column, the  
question is i like to compare the content of the model and display the  
differences in a HTML view with yellow highlighting.

R there any plugin that can solve this problem ?  
Do I need to use Regex to solve it ? cos i’m a newbie bout regex.  
I found an article

> **[Ruby on Rails Diff Text to HTML and | MarkMcB](https://markmcb.com/2008/11/04/ruby-on-rails-diff-text-to-html-ins-and-del/)**
>
> Compare their differences your HTML views.

that try to solve the problem using “diff” but apparently it needs a  
file processing, so r there a way to do it without involving any  
files ?

Thanx
