|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
Comparing 2 different chunks of text
Hi all, Is it possible to compare 2 chunk of text and highlight the difference in the second chunk?Abigail Coker 05/28/08 06:47 A > chunk comparisonDon L 05/28/08 08:21 A >// just use equality comparisonAbigail Coker 05/28/08 08:35 A He was just being a simple tool. There was no intention of that working.Bobby Hartsfield 05/28/08 09:07 A >Bobby Hartsfield -- a dispicalbe beingDon L 05/28/08 06:34 P > I tried to put up with your crap before, but enough, you are nothingWill Tomlinson 05/28/08 07:22 P I wasn't 'following up' for you or to you... I was actually giving aBobby Hartsfield 05/28/08 08:01 P A simple way to do this would be to split the chunk of text on a space, intoAndy Matthews 05/28/08 09:11 A >A simple way to do this would be to split the chunk of text on a space, intoAbigail Coker 05/28/08 09:17 A Hold on-- you had this conversation too early for me to get to work andBrad Wood 05/28/08 10:55 A OK, as promised here it is.Brad Wood 05/28/08 11:51 A >Also, I should clarify... Below I stated that it didn't perform to wellAbigail Coker 05/29/08 05:49 A Since your are adept with Java, have you done anything like that in Java?Sonny Savage 05/29/08 10:03 A >Since your are adept with Java, have you done anything like that in Java?Abigail Coker 05/29/08 10:54 A >> The everyday question for me really is what limitation CF has..Gerald Guido 05/29/08 11:49 A Hi all, Is it possible to compare 2 chunk of text and highlight the difference in the second chunk? e.g.<cfset textChunk1 = "My name is Abi"> <cfset textChunk2 = "My name is Abigail today"> comPareString(textChunk1,textChunk2) The output should then be "My name is <b>Abigail today</b>" - i.e. "Abigail today" been highlighted or whatever you want to do with the added text...is there a function in ColdFusion to this? Many thanks, Abi. ----- Excess quoted text cut - see Original Post for more ----- // just use equality comparison <cfif textChunk1 IS textChunk2> The two chucks seem from the same stock. <cfelse> You're nuts. Just kidding :) </cfif> >// just use equality comparison ----- Excess quoted text cut - see Original Post for more ----- But using equality will only tell you if they're equal or not e.g. the compare function will only return a -1,0 or 1. I was hoping that there is a function or a UDF out there that will compare two different strings and highlights the different words or character in the second string... hope it makes sense... He was just being a simple tool. There was no intention of that working. There is nothing built in to do anything like this. You may be able to find a compare/merge command line tool that you can cfexecute... else, in CF... basically what you would have to do is: 1) Remove the parts that DO match since its all you can pinpoint initially By 'remove' I mean extract and replace with a marker and store the removed text in an array so you can put it back where it goes later 2) Then what you have left is only the unmatched words/letters/numbers/punctuation etc... wrap your spanned highlight code around each of those words/numbers/etc... that are left 3) Then put the extracted parts back into their places I can think of a number of weird scenarios to throw a wrench in the 'basic' logic for something like this and foresee it getting rather involved. You'll have to ask yourself if it is worth it or not. .:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com ----- Excess quoted text cut - see Original Post for more ----- But using equality will only tell you if they're equal or not e.g. the compare function will only return a -1,0 or 1. I was hoping that there is a function or a UDF out there that will compare two different strings and highlights the different words or character in the second string... hope it makes sense... ----- Excess quoted text cut - see Original Post for more ----- I tried to put up with your crap before, but enough, you are nothing but a dispicalbe being. Try to remember this, anything I post DON'T FOLLOW UP. > I tried to put up with your crap before, but enough, you are nothing > but a dispicalbe being. Try to remember this, anything I post DON'T > FOLLOW UP. Don L, Can he follow up if only to point out your spelling errors? Will I wasn't 'following up' for you or to you... I was actually giving a legitimate reply to offer some ideas to the original poster and to point out that you were not serious since they obviously thought you were. Like most people here (and a couple other places), the last thing I wanted to do was talk to you directly... it's why most of your posts lack resolution. If you can't take a small joke then don't be such a prick all of the time... or simple tool as it were. .:.:.:.:.:.:.:.:.:.:.:.:. Bobby Hartsfield http://acoderslife.com http://cf4em.com ----- Excess quoted text cut - see Original Post for more ----- You'll >have to ask yourself if it is worth it or not. > >.:.:.:.:.:.:.:.:.:.:.:.:. >Bobby Hartsfield >http://acoderslife.com >http://cf4em.com >Bobby Hartsfield -- a dispicalbe being I tried to put up with your crap before, but enough, you are nothing but a dispicalbe being. Try to remember this, anything I post DON'T FOLLOW UP. A simple way to do this would be to split the chunk of text on a space, into an array or list. Then loop over that list and compare bit of the string individually. At that point you'd be able to tell where the changes are, if there are any. ----- Excess quoted text cut - see Original Post for more ----- But using equality will only tell you if they're equal or not e.g. the compare function will only return a -1,0 or 1. I was hoping that there is a function or a UDF out there that will compare two different strings and highlights the different words or character in the second string... hope it makes sense... >A simple way to do this would be to split the chunk of text on a space, into >an array or list. Then loop over that list and compare bit of the string >individually. At that point you'd be able to tell where the changes are, if >there are any. OK thanks guys, I was hoping there was already a solution or function out there. I'll try what you suggested Bob & Andy and post it back here if I suceed in solving the probs.. Abi Hold on-- you had this conversation too early for me to get to work and reply. :) I have a function I wrote a while back to do this. It is a variant of the LCS or Longest Common String method. I found a version online in C called SIFT3 or something and changed it to cfscript. It doesn't perform the best on long strings when you have thousands of them to compare, but at least it could give you something to start with. Give me a minute to post the code somewhere... ~Brad OK thanks guys, I was hoping there was already a solution or function out there. I'll try what you suggested Bob & Andy and post it back here if I suceed in solving the probs.. Abi OK, as promised here it is. http://www.bradwood.com/string_compare/ This is a very crude example, and I'm sure the code can be improved upon, but feel free to use it if you think it will help you. Also, I should clarify... Below I stated that it didn't perform to well when doing thousands of long string compares. That is only half true. It is slower in CF7, but when I ran it on CF8 it KICKED BUTT. I'm talking, a 3 minute page load reduced down to 13 seconds on a SLOWER server. Go CF8! ~Brad Hold on-- you had this conversation too early for me to get to work and reply. :) I have a function I wrote a while back to do this. It is a variant of the LCS or Longest Common String method. I found a version online in C called SIFT3 or something and changed it to cfscript. It doesn't perform the best on long strings when you have thousands of them to compare, but at least it could give you something to start with. Give me a minute to post the code somewhere... ~Brad >Also, I should clarify... Below I stated that it didn't perform to well >when doing thousands of long string compares. That is only half true. >It is slower in CF7, but when I ran it on CF8 it KICKED BUTT. I'm >talking, a 3 minute page load reduced down to 13 seconds on a SLOWER >server. Go CF8! >~Brad Thanks a million Brad...and guys I didn't mean to start the 3rd world war :-)..I'm really new to the CF world (8 months) having coded in Java for the past 3 years altogether I'm a new programmer, as far as web apps goes I think CF rocks and this community has to be the best for CF, it was recommended by a colleague and I'm glad he did... Since your are adept with Java, have you done anything like that in Java? It's pretty trivial to use Java objects in CF. On Thu, May 29, 2008 at 5:46 AM, Abigail Coker <agatha_coker@hotmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- >Since your are adept with Java, have you done anything like that in Java? >It's pretty trivial to use Java objects in CF. > >On Thu, May 29, 2008 at 5:46 AM, Abigail Coker <agatha_coker@hotmail.com> I wouldn't say I'm adept at Java but I'll say I'm OK, I'm Java certified but doesn't mean a great deal in the "real world" but I wouldn't go as far as saying the knowledge attained during certification and Uni is a waste, I've come to learn that nothing can buy experience, which is why I spend most of my working day here (it's my second office:-)). Going back to your question I have used a lot of string functions in Java, my initial (3 yrs) experience is in the wireless phone game industry. The web world is something totally different though and needs a different mind set I've found. I've written about 3 websites in 8 months and found myself especially in the 1st project needlessly (I think) calling Java objects anywhere and everywhere possible e.g. uploading file using the FileInputStream constructor and using method/s that comes with it when needed, when I could easily have used cffile (no one told me:-))I've since read up though....using javax.imageo....to manipulate images (very long winded) when cfimage would have sorted it out nicely in a couple of lines..the list goes on..if you search round the site you'll also see me asking a lot of question on "how do translate this from Java to CF". Hopefully once I become more adept at CF, I should be able to judge what is needed outside of CF when it comes to solutions. I think the power and "rapidity" of CF is really largely understated outside the CF world, don't really know why. The everyday question for me really is what limitation CF has.. Abi >> The everyday question for me really is what limitation CF has.. It is largely dependent of the imagination of the person using it. And being able to tap into the underlying Java lessens many of the things that CF isn't all that great at. Like sting manipulation. >> I think the power and "rapidity" of CF is really largely understated outside the CF world, don't really know why. I heard it put this way: If you want to open a bottle of wine, with Coldfusion you just open it. With other languagese you have to build the bottle opener first. My experience with other languages, namely PHP, has confirmed that (at least in my mind). A good number of third party extensions and classes found at places like phpclasses.org are for things that are built into CF. G -- "One man with courage makes a majority." -Andrew Jackson
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||