GIDForums  

Go Back   GIDForums > Computer Programming Forums > Miscellaneous Programming Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Apr-2009, 09:40
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Compare a line of text


One of the most boring tasks updating this forum script is when I have to go through the many lines of text in a template to see what, if anything, is different. The (vbulletin) script itself does this pretty well, where it can highlight each line of markup that is new, changed or missing.

But changes within a single line of text is not really handled at all. So if I have previously edited this particular line in a template with multiple additions, modifications and/or deletions, then I can't easily tell them (the modifications) apart.

For example, let us say that I have 2 different versions of a line within a template:

OLD
Code:
<p>one two three four five six</p>

NEW
Code:
<p>two three four five six seven</p>

Remember, I'm not comparing whole blocks of text here, just a single line!

Ideally, I want something that will highlight the differences between the two. I would expect the script or software to highlight the differences like this:

OLD
Code:
<p>one two three four five six</p>

NEW
Code:
<p>two three four five six seven</p>

Is there something (software) out there already able to do this? I mean, something free of course . Or if not, how would I go about writing a script for me to do this easily? Just some pseudo code would be fine.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #2  
Old 02-Apr-2009, 09:58
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Compare a line of text


Actually, I'd rather prefer the pseudo code only.

I really don't feel like installing anything on my computer that I will need only very rarely.

So I am going to go ahead and try writing something right now...
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #3  
Old 02-Apr-2009, 15:01
TurboPT's Avatar
TurboPT TurboPT is offline
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,140
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Compare a line of text


Not sure if you might have it installed, but vimdiff will highlight line differences.

I'm not sure if there is an option to only mark the two words, as you've indicated, but I'm checking...

at the prompt: vimdiff f1 f2

EDIT:
vimdiff can handle three files. I did a minor f1 f2 f3 for a simple test. Thought this might be helpful to know. (or not)
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #4  
Old 03-Apr-2009, 01:10
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Compare a line of text


Thank you for the suggestion, TurboPT, I am sure someone else will find it useful too.

Since I was already halfway through my script last night, I decided to go ahead and finish it this morning, and I am happy to announce that it actually works!

Online tool: Compare strings or text

Although it is not perfect, it will probably help me work on this site's update faster now. The results are also not what I had expected. For example, if I use the strings from my examples above, this is the output from the online tool:

OLD
Code:
<p>one two three four five six</p>


NEW
Code:
<p>two three four five six seven</p>

Of course, it is probably full of bugs as well but I hope to refine it as soon as I am done with the update (of this site). As usual, any feedback is welcome.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #5  
Old 03-Apr-2009, 01:51
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Compare a line of text


Select the 2 versions of the file in Total Commander -> File -> Compare by content

I doubt this tool totally satisfies your needs, but it can be very helpful nevertheless.

See attached.

Best regards,
Lucian
Attached Images
File Type: jpg TC Compare by content.JPG (41.7 KB, 4 views)
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 03-Apr-2009, 01:56
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Compare a line of text


Too late, now I am already happy with this online tool. And I suspect I can improve on it too...
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #7  
Old 03-Apr-2009, 02:10
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Compare a line of text


Quote:
Originally Posted by admin
Too late, now I am already happy with this online tool. And I suspect I can improve on it too...

Can you make the 2 frames wider? I am trying to test it with some production code from our SVN and it is very hard to read
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #8  
Old 03-Apr-2009, 02:16
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Compare a line of text


Widened the table that holds the results a bit. But remember, for the moment this tool only works best for a single line. I have not really done a good job handling newlines and carriage returns... yet.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #9  
Old 03-Apr-2009, 02:25
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 1,032
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: Compare a line of text


Quote:
Originally Posted by admin
Widened the table that holds the results a bit. But remember, for the moment this tool only works best for a single line. I have not really done a good job handling newlines and carriage returns... yet.

Thanks.

Indeed, when I used the content of whole files, the script duplicates some of the text in the displayed result (quite weird). But it works fine on small input. Good job
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #10  
Old 03-Apr-2009, 02:34
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 841
admin will become famous soon enough

Re: Compare a line of text


Actually, thanks to you, I found a major problem with this script! Oh well, back to the drawing board. I'll post again if I manage to fix it.

To see an example of the problem, please post:

FIRST
Code:
Widened the table that holds the results a bit. But remember, for the moment this tool only works best for a single line. I have not really done a good job handling newlines and carriage returns... yet.

SECOND
Code:
Widened teh table that holds the results a bit. But remember, for the moment this tool only works best for a single line. I have not really done a good job handling newlines and carriage returns.. yet.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Problems encountered while burning CD's RayDarkness Computer Software Forum - Windows 1 18-Nov-2006 05:54
getting an error while compiling and running using different IDE. jaro C Programming Language 0 25-Aug-2006 10:14
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 11:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 12:28
CD Buring Failed skanth2000 Computer Hardware Forum 1 15-Nov-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:39.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.