11 Replies Latest reply on Mar 9, 2012 1:44 PM by philmodjunk

    Change style using Perform Find/Replace

    KyleVanHorn

      Title

      Change style using Perform Find/Replace

      Post

      I want to do a global (all fields, all records) search and replace wherein I only change the styling of the found text.

      For example: Find all occurrences of "b.c." with no styling and replace them with "B.C." and small caps styling.

      I've included the screen shot of what I'm trying and it's not working for me.

      Any suggestions would be very appreciated.

      Cheers

      Screen_shot_2012-03-09_at_10.55.31_AM.png

        • 1. Re: Change style using Perform Find/Replace
          philmodjunk

          Looks like you should use: TextStyleAdd ( "B.C." ; smallCaps )

          • 2. Re: Change style using Perform Find/Replace
            KyleVanHorn

            Thanks for the quick input.

            I had this thought myself, but it didn't affect anything until I turned on the "Match case" switch". Even then all it does is replace lower case with upper case instead of replacing lower case with small caps.

            The find and replace is working, I think something is off about with my syntax for the TextStyleAdd function, but I have no idea what it is.

            • 3. Re: Change style using Perform Find/Replace
              philmodjunk

              I got it to work. First, an apology for my first post. You DO want lower case text inside the text style add function. All upper case letters look exactly the same with small caps formatting so you don't want to use an Upper Case B.C. here.

              Here are the options I specified in the Find/Replace dialog:

              I selected "Replace All" in the Perform drop down and "All" in the direction drop down.

              I did not specify "match case".

              The "find what" and "Replace With" boxes match what I see in yours. (Though I searched for and reformatted the word "apple" instead of "b.c.".)

              • 4. Re: Change style using Perform Find/Replace
                KyleVanHorn

                Well that's frustrating, it's still not working for me.

                The fields I'm searching have other text and multiple instances of "b.c."

                For example:

                "Controlled by Carthage, 264 b.c.; Controlled by Rome, 264 b.c.; Added to Rome, 146 b.c.; Carthagnian land added to Rome, 146 b.c."

                How might this affect my results?

                • 5. Re: Change style using Perform Find/Replace
                  philmodjunk

                  Now I can't reproduce what I had before. I think I fooled myself with that one. It looks like text styles cannot be added to the replace text.

                  I did get b.c. references styled as SmallCaps by using replace field contents with the calculation option:

                  Substitute ( YourField ; "b.c." ; textstyleadd ( "b.c." ; SmallCaps ) )

                  • 6. Re: Change style using Perform Find/Replace
                    KyleVanHorn

                    Okay, now we're getting somewhere. I was also able to get your suggestion to work:

                    Substitute ( YourField ; "b.c." ; textstyleadd ( "b.c." ; SmallCaps ) )

                    So I have a script that works for one field in one record.

                    Now I need a script to work on all fields in all records. Is there an all-inclusive entry that can be used for "YourField" in the Substitute function?

                    Thanks again for all the help.

                    • 7. Re: Change style using Perform Find/Replace
                      philmodjunk

                      Unfortunately no, you'd need a separate replace field contents step for each field where you need to make this change.

                      BTW, you can also use this calculation as an auto-enter calculation to reformat your b.c. text each time you edit the field.

                      • 8. Re: Change style using Perform Find/Replace
                        KyleVanHorn

                        Okay, here's where I ended up:

                        I have a separate script for each field where I want to perform the Substitute using this model:

                        Substitute ( YourField ; "b.c." ; textstyleadd ( "b.c." ; SmallCaps ) )

                        Then, I put a script trigger on each corresponding filed in the layout to run on exit.

                        Not the elegant solution I was hoping for, but it works.

                        Thanks again for the speedy and very helpful guidance!

                        • 9. Re: Change style using Perform Find/Replace
                          philmodjunk

                          Actually, you don't need scripts or triggers.

                          Open Manage | database | Fields and double click one of these fields to open Field Options.

                          Click the auto-enter tab.

                          Select Calculation and enter:

                          Substitute ( self ; "b.c." ; textstyleadd ( "b.c." ; SmallCaps ) )

                          Click OK

                          Clear the "do not replace existing value..." check box.

                          Now, any time you leave the field after editing it, this calculation will kick in an format any instance of  b.c. as Small caps. Note that this expression can eaily be copied and pasted without any additional editing to enable this for multiple fields.

                          • 10. Re: Change style using Perform Find/Replace
                            KyleVanHorn

                            Much nicer!

                            Not surprisingly, I needed to do the same thing with "a.d."

                            So I used this function in the Field Options as you suggested"

                            Substitute(Substitute(Self; "b.c."; TextStyleAdd ( "b.c." ; SmallCaps )); "a.d."; TextStyleAdd ( "a.d." ; SmallCaps ))

                            Works like a dream.

                            Cheers

                            • 11. Re: Change style using Perform Find/Replace
                              philmodjunk

                              You can simplify this with brackets instead of nesting one substitute inside another:

                              Substitute(Self; [ "b.c."; TextStyleAdd ( "b.c." ; SmallCaps ) ] ; [ "a.d."; TextStyleAdd ( "a.d." ; SmallCaps )] )