Re: Help with REFind and Insert()
It sounds like something else is missing. Can you post your current code? -Leigh ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350118 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
That did get rid of the error but now it isn't inserting anything. It appears to be ignoring the statement altogether. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350113 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
> ie found = REFind(url.terms, DocContents, startAt, TRUE ); >-Le lol.. Even my name is being truncated ; ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350111 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
Did you forget to modify reFind so it returns subexpressions (ie a structure not a number)? ie found = REFind(url.terms, DocContents, startAt, TRUE ); -Le ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350109 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
When I put in the found.pos[1]-1 I get "You have attempted to dereference a scalar variable of type class java.lang.Integer as a structure with members" Whatever that is supposed to mean? > Looks like my last reply was truncated. (Out of curiosity, I am > resending a cfscript version to see if the lack of tags makes a > difference.) > > startAt = 1; > for (i = 1; i <= ArrayLen(getMatches); i++) { > found = REFind(url.terms, DocContents, startAt, true); > // insert *before* the matching string > DocContents = Insert( i, DocContents, found.pos[1]-1); > // shift starting position forward to ensure we find a *new* > occurrence > startAt = found.pos[1] + found. len ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350107 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
Looks like my last reply was truncated. (Out of curiosity, I am resending a cfscript version to see if the lack of tags makes a difference.) startAt = 1; for (i = 1; i <= ArrayLen(getMatches); i++) { found = REFind(url.terms, DocContents, startAt, true); // insert *before* the matching string DocContents = Insert( i, DocContents, found.pos[1]-1); // shift starting position forward to ensure we find a *new* occurrence startAt = found.pos[1] + found.len ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350098 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
A lot depends on the search pattern. But as you loop keep track of where the previous occurrence was found. Then start searching *after* that position. Otherwise, refind will just return the first occurrence over and over again. You can use the fourth parameter of reFind to get the position and length of the string found ie reFind(pattern, string, startPosition, returnSubExpression). Then use those values to shift the starting search position forward each time you loop. http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e9a.html Not highly tested, but something along these lines http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350097 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
So, any suggestions how to go about that? I just want to highlight words in a searched document and allow the user to go to next and previous match in long documents. I thought adding a would be a good way using an Insert function. Now, I'm clueless on how to go about it. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350096 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
> REFind( url.terms, DocContents, ...) Also the code probably will not behave as expected if you are searching for partial words. Since you are searching starting from the beginning of the string each time, rather than the last occurrence. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350095 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
> inserts the number in the wrong spot. Insert adds the string *after* the given position, not before. So you need to deduct 1 from the result of reFind() ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350094 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
Thanks Carl, Now it just ignores it altogether and doesn't put any number in at all. ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350093 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Re: Help with REFind and Insert()
The docs for REFind() say that the third argument should be a positive integer, default value is 1. REFind() returns the position in the string where the matched string begins. You'll need to add the length of the matched string (in your case, Len(url.terms) ) to this value to get the end of the matched string. Try this: HTH, -Carl ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350092 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm
Help with REFind and Insert()
I've been banging my head on this all day. All I want to do is put a number to the left of each word that I find in my document so that I can eventually turn those into links to jump from one match to the next. I have it partially working. Here is my code: What happens is, I put in coldfusion as a search term and it inserts the number in the wrong spot. So it would be c1oldfusion, c2oldfusion, c3oldfusion, etc. Anyone ever experience this before? ~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:350089 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm