July 14, 200619 yr From within a script, I would like to find all the instances of a certain word (defined with a variable $curWord) within a field and change their font color to blue. I have tried "Perform Find/Replace", "Substitute", and a combination of "LeftWords" & "MiddleWords" & "RightWords". Each of these methods comes with its own downfalls. "LeftWords()" sometimes eats punctuation. "Substitute" replaces WITHIN other words instead of just whole words. "Find/Replace" won't seem to change the color of the found word. Any suggestions or pointers to where I have gone wrong? Thank you all for any help you can provide. Nancy Edited July 14, 200619 yr by Guest
July 15, 200619 yr Hi you don't need a script to make what you wish... For example, we have 2 text fields: 1)"what" where we'll put the word to search 2)"text" ( an [color:red]Auto-Enter/Replace field) where there is the text, with option to auto-enter this calc: [color:blue]Let([ adjustedText = "|" & Substitute ( TextColorRemove ( text ) ; " "; "|" ) & "|"; search = "|" & what & "|" ]; Trim ( Substitute ( Substitute ( adjustedText ; search; TextColor ( search ; RGB ( 0 ; 0 ; 255 ) ) ) ; "|" ; " " ) ) ) Note that the resul is "case sensitive", so if you'll search for "New", the word "new" will never change its color. Also, if the "what" field is turned to empty, the text becames black ! ( or whatever color it was before ) BTW: if you really want to use a script, the same calc is all you need to insert into a Set Field script step.
July 15, 200619 yr Author Daniele, Thank you very much for your help. What I ended up doing was using a "Find/Replace" script step to append 'xxx' onto each word I needed to change the color of. THEN I used the "Substitute" script step to change the color. Kind of a kludge, but it did the job. -) Nancy
July 15, 200619 yr Ok. But what you have made is something like this calc: Let([ search = what & "xxx"; adjustedText = Substitute ( TextColorRemove ( text ) ; what; search) ]; Substitute ( adjustedText ; search; TextColor ( what ; RGB ( 0 ; 0 ; 255 ) ) ) ) This will find also [color:red]portions of a word and you said: ""Substitute" replaces WITHIN other words instead of just whole words. " Try to search for "[color:red]on" in your text ! You'll have "[color:blue]on", functi"[color:blue]on" , calculati"[color:blue]on"s and so "[color:blue]on" ! So it's better to put "something" where there was a space and the same "something" before the text and at the end of the text. I did it with " | ", but "xxx" is the same. EDIT: if the Perform Find/Replace script step is setted to "match whole words only" you had found the correct way :P Edited July 15, 200619 yr by Guest
July 15, 200619 yr I got this from Ray Cologons web site, Night Wing Enterprises. It may have some features you are looking for. [color:blue]Auto Bold HTH Al [color:blue]It is suggested that you provide a link to a file which is presented on someone's website rather than attaching their files. In this way, the author can update his file without worrying about another copy attached elsewhere. And it draws people to their website which, in a small way, repays them for providing us with knock-out demos. [color:blue]LaRetta -) Edited July 15, 200619 yr by Guest Removed demo and attached link to NightWing file.
Create an account or sign in to comment