Macaddict Posted July 14, 2006 Posted July 14, 2006 (edited) 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, 2006 by Guest
Raybaudi Posted July 15, 2006 Posted July 15, 2006 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.
Macaddict Posted July 15, 2006 Author Posted July 15, 2006 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
Raybaudi Posted July 15, 2006 Posted July 15, 2006 (edited) 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, 2006 by Guest
aldipalo Posted July 15, 2006 Posted July 15, 2006 (edited) 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, 2006 by Guest Removed demo and attached link to NightWing file.
Recommended Posts
This topic is 6706 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now