this might be a little easier
//////////////////////////////////////////////////////////
<cfset originalList = "a this is the original sentence">
<cfset modifiedList = "this is my new sentence and its really good">
<cfscript>
function listCompare()
{
origList = Arguments[1];
newList = Arguments[2];
if (ArrayLen(Arguments) EQ 3)
{delim = Arguments[3];}
else
{delim = ",";}
// Convert to array
origListArray = ListToArray(origList);
// Convert to array
newListArray = ListToArray(newList,delim);
// Create result struct
result = structNew();
result.origianlList = ListToArray(origList,delim);
result.newList = ListToArray(newList,delim);
result.added = ArrayNew(1);
result.remained = ArrayNew(1);
// Create tmp list to hold origianl values
tmpList = origList;
for (i = 1; i LTE ArrayLen(newListArray); i=i+1)
{
// Ad the item been added?
if (NOT listFindNoCase(origList,newListArray[i],delim))
{ArrayAppend(result.added,newListArray[i]);}
// Does it exists in both lists?
if (listFindNoCase(origList,newListArray[i],delim))
{ArrayAppend(result.remained,newListArray[i]);}
if (listFindNoCase(tmpList,newListArray[i],delim))
{tmpList =
ListDeleteAt(tmpList,listFindNoCase(tmpList,newListArray[i],delim),delim);}
}
// Populate result for removed items
result.removed = ListToArray(tmpList,delim);
return result;
}
</cfscript>
<cfdump var="#listCompare(originalList,modifiedList," ")#">
///////////////////////////////////////////////
This will return a structure to you containing whats been added, whats been
removed, what has remained from the origial string, the origianl string and
the new string.
You can also pass in a delimiter value, but the default is a comma
Have fun
Regards
Steve Onnis
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Matthew
Walker
Sent: Wednesday, February 11, 2004 11:27 AM
To: CFAussie Mailing List
Subject: [cfaussie] RE: Compare - display changes
This looks promising: http://www.ics.uci.edu/~eppstein/161/960229.html
I've been playing around with it. Got to this point (i.e. shows the longest
common subsequence but not the diff markup). Still experimenting....
<cfset str1 = "a quijk borwn fox jumped way over the lazy dog">
<cfset str2 = "The quick brown fox jumped over the lazy dog!">
<cfset arr1 = listToArray(str1, " ")>
<cfset arr2 = listToArray(str2, " ")>
<cfset results = arrayNew(2)>
<cfoutput>#lcs_length2(1, 1)#</cfoutput>
<cfscript>
function lcs_length(posInArr1, posInArr2) {
var result = 0;
if ( results[posInArr1][posInArr2] neq -1 )
return results[posInArr1][posInArr2];
if ( (posInArr1 gt arrayLen(arr1)) or (posInArr2 gt
arrayLen(arr2)) )
result = 0;
else
if ( arr1[posInArr1] eq arr2[posInArr2] )
result = 1 + lcs_length(posInArr1+1,
posInArr2+1);
else
result =
max(lcs_length(posInArr1+1,posInArr2), lcs_length(posInArr1,posInArr2+1));
results[posInArr1][posInArr2] = result;
return result;
}
function lcs_length2(posInArr1, posInArr2) {
for ( i = arrayLen(arr1)+1; i gte 1; i=i-1 )
for (j = arrayLen(arr2)+1; j gte 1; j=j-1 ) {
if ( (i gt arrayLen(arr1)) or (j gt arrayLen(arr2))
)
results[i][j] = 0;
else
if ( arr1[i] eq arr2[j] )
results[i][j] = 1 +
results[i+1][j+1];
else
results[i][j] = max(results[i+1][j],
results[i][j+1]);
}
return results[1][1];
}
</cfscript>
<cfset sequence = "">
<cfset i = 1>
<cfset j = 1>
<cfset notDone = true>
<cfloop condition="#notDone#">
<cfif arr1[i] eq arr2[j]>
<cfset sequence = listAppend(sequence, arr1[i], " ")>
<cfset i = i + 1>
<cfset j = j + 1>
<cfelseif results[i+1][j] gte results[i][j+1]>
<cfset i = i + 1>
<cfelse>
<cfset j = j + 1>
</cfif>
<cfset notDone = ((i lte arrayLen(arr1)) and (j lte
arrayLen(arr2)))>
</cfloop>
<cfoutput>#sequence#</cfoutput>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:bounce-cfaussie-
> [EMAIL PROTECTED] On Behalf Of Taco Fleur
> Sent: Wednesday, 11 February 2004 12:19 p.m.
> To: CFAussie Mailing List
> Subject: [cfaussie] RE: Compare - display changes
>
> allright, I have quickly put something together and came up with the
> following solution to display modified values from dropdowns, but I still
> have no good method to display differences between strings.
>
> I am thinking of performing the compareNoCase on the strings but that
> still will only show whether there is a difference, not what is different,
> i.e. deleted or added... (I might even use the MS SQL DIFFERENCE keyword
> instead and perform this within the db)
>
> I am looking for some input, ideas and better ways... ;-))
>
>
> Summary: I have an original resultset (unmodified) and a modified
> resultset (actually wddx package), I'd like to display to the user what
> the differences are in detail (as much detail as possible).
>
>
> <cfset originalList = "1,2,3,4,5,55">
> <cfset modifiedList = "2,5,7">
>
> <cfscript>
> function fnListToQuery( columnName, list )
> {
> var objQuery = queryNew(columnName);
> for ( i = 1; i LTE listLen(list); i = i + 1 )
> {
> queryAddRow(objQuery, 1);
> querySetCell(objQuery, "id", listGetAt(list, i), i);
> }
> return objQuery;
> }
> </cfscript>
>
> <cfset objQuery = fnListToQuery( "id", originalList )>
> <cfset objQuery2 = fnListToQuery( "id", modifiedList )>
>
> <cfquery dbtype="query" name="qTest">
> SELECT *
> FROM objQuery
> WHERE (id NOT IN(#modifiedList#))
> </cfquery>
>
> <cfquery dbtype="query" name="qTest2">
> SELECT *
> FROM objQuery2
> WHERE (id NOT IN(#originalList#))
> </cfquery>
>
> <cfoutput>
> <p>
> <cfloop query="qTest">
> Deleted: #qTest.id#<br>
> </cfloop>
> <cfloop query="qTest2">
> Added: #qTest2.id#<br>
> </cfloop>
> </p>
>
> I might even do the above within the RDMBS instead of CF.....
>
>
> Taco Fleur
> 07 3535 5072
> Blog: http://www.tacofleur.com/index/blog/
> Methodology: http://www.tacofleur.com/index/methodology/
> Tell me and I will forget
> Show me and I will remember
> Teach me and I will learn
>
>
> -----Original Message-----
> From: Mark Stanton [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 11 February 2004 9:17 AM
> To: CFAussie Mailing List
> Subject: [cfaussie] RE: Compare - display changes
>
>
> > Cheers for the calendar, but I think it was Rob who was after
> > a calendar ;-))
>
> Sorry too early for my brain to be properly in gear yet :)
>
>
>
> Cheers
>
> Mark
>
>
> ------------------
> Mark Stanton
> Technical Director
> Gruden Pty Ltd
> Tel: 9956 6388
> Mob: 0410 458 201
> Fax: 9956 8433
> http://www.gruden.com
>
>
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to leave-cfaussie-
> [EMAIL PROTECTED]
>
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004
>
> ---
> You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
> To unsubscribe send a blank email to leave-cfaussie-
> [EMAIL PROTECTED]
>
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
> http://www.mxdu.com/ + 24-25 February, 2004
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004
---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]
MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004