Loading ...
Sorry, an error occurred while loading the content.

How to replace text in a string with clipcode?

Expand Messages
  • Sherry
    It s funny, I have worked with NoteTab Pro for a month and still can t find a tutorial for Clipcode! A simple Hello World type code tutorial? I d like some
    Message 1 of 12 , Aug 13, 2010
    • 0 Attachment
      It's funny, I have worked with NoteTab Pro for a month and still can't find a tutorial for Clipcode! A simple Hello World type code tutorial? I'd like some hints for that! Not just a pointer to a file full of complicated clipcode. Maybe a short 5 min video tutorial with a simplest of all examples? Just a suggestion.

      My question is: How do I write a clip code that will replace all occurrences of _ with a space and then capitalize all words?

      for example

      "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"

      or maybe not replace in a string, but instead replace within a highlighted piece of text.

      Replacement in place is fine.

      Thanks in advance! I feel clipcode is a really valuable concept but extremely tough to crack into! For example, I am proficient with Xemacs macros, and they are easy to define.... at least for me!

      Thanks again! Sherry
    • John Shotsky
      Clipcode can seem daunting at first, but it becomes clearer as you practice with it. My method was to take working clips and run them on text to see what they
      Message 2 of 12 , Aug 14, 2010
      • 0 Attachment
        Clipcode can seem daunting at first, but it becomes clearer as you practice with it. My method was
        to take working clips and run them on text to see what they do, then modify them to do what I want.
        Eventually, I learned to create my own, but I still ask here at this group when I'm stumped. That's
        what this group is for.

        One valuable resource is books on regular expressions - I have several, and often refer to them when
        trying something new. NoteTab uses the PCRE flavor of regular expressions, so if you Google for PCRE
        regular expressions, you will find many sources of information.

        To solve your problem, I would take it in two steps - one to replace the underscores, and one to
        capitalize the words. There is actually a toolbar method for the latter.

        To replace the underscores:
        ^!Replace "\_" >> "\x20" ARSTW
        That simply says to place a space where there is an underscore throughout the document. The \x20 is
        an alternate way of writing a space, and is more obvious when reviewing your code. You'll find it
        helpful if you have NoteTab set to show non-printing characters, so you can actually 'see' spaces,
        tabs, CR's and the like.

        Then the simplest method to do this one time would be to use the toolbar 'Capitalize' button. Select
        all text (Ctrl-A) or whatever text you want converted, and use Capitalize, which will do as you
        requested. If you need to do this repeatedly, then a clip can be fashioned with a loop to do it for
        you.

        Regards,
        John

        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Sherry
        Sent: Friday, August 13, 2010 23:48
        To: ntb-clips@yahoogroups.com
        Subject: [Clip] How to replace text in a string with clipcode?


        It's funny, I have worked with NoteTab Pro for a month and still can't find a tutorial for Clipcode!
        A simple Hello World type code tutorial? I'd like some hints for that! Not just a pointer to a file
        full of complicated clipcode. Maybe a short 5 min video tutorial with a simplest of all examples?
        Just a suggestion.

        My question is: How do I write a clip code that will replace all occurrences of _ with a space and
        then capitalize all words?

        for example

        "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"

        or maybe not replace in a string, but instead replace within a highlighted piece of text.

        Replacement in place is fine.

        Thanks in advance! I feel clipcode is a really valuable concept but extremely tough to crack into!
        For example, I am proficient with Xemacs macros, and they are easy to define.... at least for me!

        Thanks again! Sherry



        [Non-text portions of this message have been removed]
      • Axel Berger
        ... Every one of us went through that phase. Regardless of what language(s) you ve know before, Clips seems very strange at first. Looking at tips here, you ll
        Message 3 of 12 , Aug 14, 2010
        • 0 Attachment
          Sherry wrote:
          > I feel clipcode is a really valuable concept but extremely tough

          Every one of us went through that phase. Regardless of what language(s)
          you've know before, Clips seems very strange at first. Looking at tips
          here, you'll find nearly everybody only uses a subset of commands he's
          become familiar with, I do.

          > "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"

          ^!Jump TEXT_START
          :loop
          ^!Find "\_\w" RST
          ;^!Continue
          ^!IfError fertig
          ^!InsertSelect ^$StrReplace("_";" ";"^$GetSelection$";False;False)$
          ;^!Continue
          ^!InsertText ^$StrUpper("^$GetSelection$")$
          ;^!Continue
          ^!Goto loop
          :fertig

          This is rather simple minded and ignores the first letter. To do more
          I'd need to know more about the regularities of your string (does it
          always have four underscores and always two letters betrween?) and how
          it relates to surrounding text.
        • flo.gehrke
          ... I doubt that this approach is the best lesson we could give to a beginner... 1. It doesn t capitalize the first letter of the string, so aa remains aa .
          Message 4 of 12 , Aug 14, 2010
          • 0 Attachment
            --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
            >
            > > "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"
            >
            > ^!Jump TEXT_START
            > :loop
            > ^!Find "\_\w" RST
            > ;^!Continue
            > ^!IfError fertig
            > ^!InsertSelect ^$StrReplace("_";" ";"^$GetSelection$";False;False)$
            > ;^!Continue
            > ^!InsertText ^$StrUpper("^$GetSelection$")$
            > ;^!Continue
            > ^!Goto loop
            > :fertig

            I doubt that this approach is the best lesson we could give to a beginner...

            1. It doesn't capitalize the first letter of the string, so 'aa' remains 'aa'.

            2. The underscore '_' is no metacharacter, so there's no need to escape it here. (This goes to John as well.)

            3. Since a pure RegEx is used here, the T option doesn't make any sense.

            4. It was asked to limit the job to selected text whereas this clip affects the whole document.

            5. Why using ^!Find and that whole loop if the whole job would be done with...

            ^!Replace "_" >> "^%Space%" HATS
            ^!Toolbar Capitalize

            (limited to selected text).

            Regards,
            Flo
          • Axel Berger
            ... All your points are valid except this one. We are not told anything about the context, but my presumption is, this kind of string will occur many times in
            Message 5 of 12 , Aug 14, 2010
            • 0 Attachment
              "flo.gehrke" wrote:
              > 5. Why using ^!Find and that whole loop if the whole job would be done with...
              > ^!Replace "_" >> "^%Space%" HATS
              > ^!Toolbar Capitalize
              > (limited to selected text).

              All your points are valid except this one. We are not told anything
              about the context, but my presumption is, this kind of string will occur
              many times in a longish document. If there was a need to highlight all
              of them individually first, we may as well drop the whole clip idea and
              do it all manually.

              > 1. It doesn't capitalize the first letter of the string, so 'aa' remains 'aa'.

              I said so myself. To tackle that one, I'd prefer to know more about the
              problem and its context. Selecting perhaps hundreds of instances by hand
              is not help at all IMHO.

              Axel
            • hsavage
              ... can t find a tutorial for Clipcode! A simple Hello World type code tutorial? I d like some hints for that! Not just a pointer to a file full of complicated
              Message 6 of 12 , Aug 14, 2010
              • 0 Attachment
                Sherry wrote:
                > It's funny, I have worked with NoteTab Pro for a month and still
                can't find a tutorial for Clipcode! A simple Hello World type code
                tutorial? I'd like some hints for that! Not just a pointer to a file
                full of complicated clipcode. Maybe a short 5 min video tutorial with
                a simplest of all examples? Just a suggestion.
                >
                > My question is: How do I write a clip code that will replace all
                occurrences of _ with a space and then capitalize all words?
                >
                > for example
                >
                > "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"
                >
                > or maybe not replace in a string, but instead replace within a
                highlighted piece of text.
                >
                > Replacement in place is fine.
                >
                > Thanks in advance! I feel clipcode is a really valuable concept
                but extremely tough to crack into! For example, I am proficient with
                Xemacs macros, and they are easy to define.... at least for me!
                >
                > Thanks again! Sherry

                Sherry,

                Reg-exp has been pretty well covered for your problem. Here's a
                simple clip language method to resolve your request.

                It does nothing more or less than you asked with your example. I
                hope you can copy and paste this into a library to use, if you don't
                know how reply back to this clips list.

                ----------------------------------
                H="Replace Underscore & Capitalize"
                ;_WITHOUT REG-EXP
                ;_
                ^!If ^$GetSelSize$ = 0 NEXT ELSE SOMETHING_SELECTED
                :NOTHING_SELECTED
                ;_With nothing selected this 3 line group executes whole document
                ^!Replace "_" >> " " TWSA
                ^!Select ALL
                ^!GoTo END
                ;_
                :SOMETHING_SELECTED
                ^!If ^$GetSelSize$ > 0 NEXT ELSE END
                ;_With selection made these last 2 lines execute on selected text
                ^!Replace "_" >> " " THSA
                :END
                ^$StrCapitalize("^$GetSelection$")$
                ------------------------------------

                ·············································
                ºvº SL_day# 226 - created 2010.08.14_17.15.01

                Party Etiquette; Drinking Your Fair Share.

                € hrs € hsavage € pobox € com
              • Eb
                I d like to add a couple of points to Flo s comments. ... Using a RegExp is definitely NOT a beginner-level tool in the first place. ... Instead of Toolbar,
                Message 7 of 12 , Aug 16, 2010
                • 0 Attachment
                  I'd like to add a couple of points to Flo's comments.


                  --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                  >
                  > I doubt that this approach is the best lesson we could give to a beginner...

                  > 3. Since a pure RegEx is used here, the T option doesn't make any sense.

                  Using a RegExp is definitely NOT a beginner-level tool in the first place.



                  > ^!Replace "_" >> "^%Space%" HATS
                  > ^!Toolbar Capitalize

                  Instead of Toolbar, the Menu command would be better, because it is much easier to find it's available options:

                  ^!Replace "_" >> "^%Space%" HATS
                  ^!Menu Modify/"Text Case"/Capitalize

                  As to a tutorial, clicking on the SECOND help itme in NoteTab (Help on Clip Programming) leads you to an excellent tutorial, albeit you will actually have to read stuff without pictures ;-).
                  Read the introductions of each topic, skim through the various commands and functions may get you started.

                  I have always thought that NoteTabs help is far superior to the average software help (a la Microsoft: "Check the 'Snaggle' option to enable 'snaggle'"). Its only major flaw is, that the list of help topics in Clip Programming is not alphabetized, making it difficult to find things.

                  On the other hand, the existing topics are roughly in the order of importance for a beginner.



                  Cheers,

                  Eb.
                • Don
                  ... And the group support here is second to none! But having said that, any suggested solution is help being given so let s not be too critical of each others
                  Message 8 of 12 , Aug 16, 2010
                  • 0 Attachment
                    > I have always thought that NoteTabs help is far superior to the average software help (a la Microsoft: "Check the 'Snaggle' option to enable 'snaggle'"). Its only major flaw is, that the list of help topics in Clip Programming is not alphabetized, making it difficult to find things.
                    >
                    And the group support here is second to none!

                    But having said that, any suggested solution is help being given so let's not be too critical of each others volunteer offers of help is my suggestion.
                  • Axel Berger
                    ... There is an alphabetic list with one important snag: ^? , the details of which I always forget, is not in it and quite hard to find every time, meaning
                    Message 9 of 12 , Aug 16, 2010
                    • 0 Attachment
                      Eb wrote:
                      > On the other hand, the existing topics are roughly in the order
                      > of importance for a beginner.

                      There is an alphabetic list with one important snag: "^?", the details
                      of which I always forget, is not in it and quite hard to find every
                      time, meaning the /obvious place/ "variables" is not that obvious to me.

                      But far more important to this thread, we seem to have lost Sherry,
                      which is a shame. I still believe any solution that forces her to
                      highlight each and every occurrence of the string manually is no help at
                      all, but I do need more input to provide a solution that is.

                      N.B: My clips tend to be rather primitive and brain dead on purpose,
                      e.g. using several primitive lines when a single one would suffice. It
                      not only makes them more easily legible for beginners but also for
                      myself, when I need to remind myself, what that clip, written months
                      ago, actually does. I admire diodeom's one-liners but for me at least,
                      they are quite hard to understand.

                      Sherry, if you're still with us: don't be put off by our internal digs
                      between the "experts", we're really all trying to help.

                      Axel
                    • flo.gehrke
                      ... Eb, For a better overview, Ray Fitzgerald created his ToolTips.CLB, last updated in Feb 2000. It s in the ClipClass+Clip Basics+more.ZIP file that Alec
                      Message 10 of 12 , Aug 17, 2010
                      • 0 Attachment
                        --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@...> wrote:

                        > > ^!Replace "_" >> "^%Space%" HATS
                        > > ^!Toolbar Capitalize
                        >
                        > Instead of Toolbar, the Menu command would be better, because it
                        > is much easier to find it's available options:
                        >
                        > ^!Replace "_" >> "^%Space%" HATS
                        > ^!Menu Modify/"Text Case"/Capitalize

                        Eb,

                        For a better overview, Ray Fitzgerald created his ToolTips.CLB, last updated in Feb 2000. It's in the ClipClass+Clip Basics+more.ZIP file that Alec uploaded to the File section of this group in Dec 2008.

                        I found it quite useful. Checking it against the latest ^!Toolbar options in NT 6.2, I found two issues:

                        1. "Printer Settings" doesn't work in NT 6.2 and returns an error message. So you better delete it.

                        2. There is a "Page Setup" option in NT 6.2 but not in that clipbook. One may add this option in order to see all valid options.

                        Regards,
                        Flo
                      • Eb
                        Thanks, Flo, I agree, and the most useful file, Toolbar.txt contains the descriptions missing from the NoteTab Help file. The clip library isn t bad either,
                        Message 11 of 12 , Aug 20, 2010
                        • 0 Attachment
                          Thanks, Flo,

                          I agree, and the most useful file, "Toolbar.txt" contains the descriptions missing from the NoteTab Help file.

                          The clip library isn't bad either, though somewhat confusing.

                          See the "Help with clips" post for a suggestion to clippers, how to avoid such confusion.



                          Cheers,

                          Eb


                          --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                          >
                          > --- In ntb-clips@yahoogroups.com, "Eb" <ebbtidalflats@> wrote:
                          >
                          > > > ^!Replace "_" >> "^%Space%" HATS
                          > > > ^!Toolbar Capitalize
                          > >
                          > > Instead of Toolbar, the Menu command would be better, because it
                          > > is much easier to find it's available options:
                          > >
                          > > ^!Replace "_" >> "^%Space%" HATS
                          > > ^!Menu Modify/"Text Case"/Capitalize
                          >
                          > Eb,
                          >
                          > For a better overview, Ray Fitzgerald created his ToolTips.CLB, last updated in Feb 2000. It's in the ClipClass+Clip Basics+more.ZIP file that Alec uploaded to the File section of this group in Dec 2008.
                          >
                          > I found it quite useful. Checking it against the latest ^!Toolbar options in NT 6.2, I found two issues:
                          >
                          > 1. "Printer Settings" doesn't work in NT 6.2 and returns an error message. So you better delete it.
                          >
                          > 2. There is a "Page Setup" option in NT 6.2 but not in that clipbook. One may add this option in order to see all valid options.
                          >
                          > Regards,
                          > Flo
                          >
                        • Sherry
                          Hello, Thank you so much, EVERYONE, for answering my request. I am sorry for not responding earlier. But I did read the discussion and finally today I am in
                          Message 12 of 12 , Aug 22, 2010
                          • 0 Attachment
                            Hello,

                            Thank you so much, EVERYONE, for answering my request. I am sorry for not responding earlier. But I did read the discussion and finally today I am in the need of the code.

                            Again, I am sorry for not communicating earlier, requiring you to read my mind ;)

                            I picked this code below, and, having inserted it into my HTML.clb library, it works like a charm. (Had to get admin privileges to add/modify the library). That is exactly what I wanted. Someday when I need more, I will study the code and modify if needed.

                            I really appreciate the responsiveness of everyone in the group, you guys rock! There is something very satisfying to have a simple code do wonders with my text ;)

                            Greetings, and have a great rest of the weekend!

                            Sherry

                            --- In ntb-clips@yahoogroups.com, hsavage <hsavage@...> wrote:
                            >
                            > Sherry wrote:
                            > > It's funny, I have worked with NoteTab Pro for a month and still
                            > can't find a tutorial for Clipcode! A simple Hello World type code
                            > tutorial? I'd like some hints for that! Not just a pointer to a file
                            > full of complicated clipcode. Maybe a short 5 min video tutorial with
                            > a simplest of all examples? Just a suggestion.
                            > >
                            > > My question is: How do I write a clip code that will replace all
                            > occurrences of _ with a space and then capitalize all words?
                            > >
                            > > for example
                            > >
                            > > "aa_bb_cc_dd_ee" should be replaced by "Aa Bb Cc Dd Ee"
                            > >
                            > > or maybe not replace in a string, but instead replace within a
                            > highlighted piece of text.
                            > >
                            > > Replacement in place is fine.
                            > >
                            > > Thanks in advance! I feel clipcode is a really valuable concept
                            > but extremely tough to crack into! For example, I am proficient with
                            > Xemacs macros, and they are easy to define.... at least for me!
                            > >
                            > > Thanks again! Sherry
                            >
                            > Sherry,
                            >
                            > Reg-exp has been pretty well covered for your problem. Here's a
                            > simple clip language method to resolve your request.
                            >
                            > It does nothing more or less than you asked with your example. I
                            > hope you can copy and paste this into a library to use, if you don't
                            > know how reply back to this clips list.
                            >
                            > ----------------------------------
                            > H="Replace Underscore & Capitalize"
                            > ;_WITHOUT REG-EXP
                            > ;_
                            > ^!If ^$GetSelSize$ = 0 NEXT ELSE SOMETHING_SELECTED
                            > :NOTHING_SELECTED
                            > ;_With nothing selected this 3 line group executes whole document
                            > ^!Replace "_" >> " " TWSA
                            > ^!Select ALL
                            > ^!GoTo END
                            > ;_
                            > :SOMETHING_SELECTED
                            > ^!If ^$GetSelSize$ > 0 NEXT ELSE END
                            > ;_With selection made these last 2 lines execute on selected text
                            > ^!Replace "_" >> " " THSA
                            > :END
                            > ^$StrCapitalize("^$GetSelection$")$
                            > ------------------------------------
                            >
                            > ·············································
                            > ºvº SL_day# 226 - created 2010.08.14_17.15.01
                            >
                            > Party Etiquette; Drinking Your Fair Share.
                            >
                            > € hrs € hsavage € pobox € com
                            >
                          Your message has been successfully submitted and would be delivered to recipients shortly.