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

Re: [Clip] Changing case using a Replace

Expand Messages
  • Axel Berger
    ... No, but why don t you do it far more simply? ^!Replace sliced Sliced WASTI Axel
    Message 1 of 12 , Mar 2, 2010
      John Shotsky wrote:
      > Can anyone see what I'm doing wrong?

      No, but why don't you do it far more simply?

      ^!Replace "<I>sliced" >> "<I>Sliced" WASTI

      Axel
    • John Shotsky
      Because it is the first lower case letter, regardless of what word it is. That s why the range is there. Regards, John From: ntb-clips@yahoogroups.com
      Message 2 of 12 , Mar 2, 2010
        Because it is the first lower case letter, regardless of what word it is.
        That's why the range is there.



        Regards,

        John



        From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf
        Of Axel Berger
        Sent: Tuesday, March 02, 2010 11:08 AM
        To: ntb-clips@yahoogroups.com
        Subject: Re: [Clip] Changing case using a Replace





        John Shotsky wrote:
        > Can anyone see what I'm doing wrong?

        No, but why don't you do it far more simply?

        ^!Replace "<I>sliced" >> "<I>Sliced" WASTI

        Axel





        [Non-text portions of this message have been removed]
      • Axel Berger
        ... Sorry, I misunderstood. You can t use functions in replace, it s a limit I ve stumbled against often enough. The only solution is a loop: ^!Jump TEXT_START
        Message 3 of 12 , Mar 2, 2010
          John Shotsky wrote:
          > regardless of what word it is.

          Sorry, I misunderstood. You can't use functions in replace, it's a limit
          I've stumbled against often enough. The only solution is a loop:

          ^!Jump TEXT_START
          :loop
          ^!Find "^\<I\>([a-z])" HRS1
          ;^!Continue
          ^!IfError clean
          ^!InsertText ^$StrUpper("^$GetSelection$")$
          ^!Goto loop
          :clean

          This is a construct I use quite often. On big texts in the thousands of
          lines InsertText becomes extremely slow.

          Axel
        • John Shotsky
          Yes, that s why I was trying to avoid a loop. 200,000+ line text. I use the loop many places, and it s an awful time penalty. Some of my files take over 10
          Message 4 of 12 , Mar 2, 2010
            Yes, that's why I was trying to avoid a loop. 200,000+ line text.



            I use the loop many places, and it's an awful time penalty. Some of my
            files take over 10 minutes to run. I thought maybe someone had thought of a
            cool way around the loop construct.



            Regards,

            John



            From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf
            Of Axel Berger
            Sent: Tuesday, March 02, 2010 12:29 PM
            To: ntb-clips@yahoogroups.com
            Subject: Re: [Clip] Changing case using a Replace





            John Shotsky wrote:
            > regardless of what word it is.

            Sorry, I misunderstood. You can't use functions in replace, it's a limit
            I've stumbled against often enough. The only solution is a loop:

            ^!Jump TEXT_START
            :loop
            ^!Find "^\<I\>([a-z])" HRS1
            ;^!Continue
            ^!IfError clean
            ^!InsertText ^$StrUpper("^$GetSelection$")$
            ^!Goto loop
            :clean

            This is a construct I use quite often. On big texts in the thousands of
            lines InsertText becomes extremely slow.

            Axel





            [Non-text portions of this message have been removed]
          • Sheri
            ... [snip] ... Another solution invokes 26 ^!Replace-all s: H= singlecharup ^!Set %finddec%=96 ... ^!Inc %finddec% ^!If ^%finddec% 122 Out ^!Set
            Message 5 of 12 , Mar 2, 2010
              --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
              >
              > John Shotsky wrote:
              > > regardless of what word it is.
              >

              [snip]

              > ^!InsertText ^$StrUpper("^$GetSelection$")$
              > ^!Goto loop
              > :clean
              >
              > This is a construct I use quite often. On big texts in the
              > thousands of lines InsertText becomes extremely slow.

              Another solution invokes 26 ^!Replace-all's:

              H="singlecharup"
              ^!Set %finddec%=96
              :loop
              ^!Inc %finddec%
              ^!If ^%finddec%>122 Out
              ^!Set %findchar%=^$dectochar(^%finddec%)$
              ^!Set %replchar%=^$DecToChar(^$Calc(^%finddec%-32)$)$
              ^!Replace "^<I>\K^%findchar%" >> "^%replchar%" RAWS
              ^!Goto loop
              :Out

              NoteTab lets you reproduce (but not transform) the whole match ($0) and/or substrings ($1, etc.) as part of the replacement text. If above is not fast enough, you can call another script or utility from inside your clip. I like Powerpro because it uses the same PCRE version as NoteTab, but has case-transforming capability in its replace-all equivalent. Some examples can be found in the archives.

              Regards,
              Sheri
            • Axel Berger
              ... It s not the loop as far as I can ascertain, it is the ^$GetSelection$ and the ^!InsertText. The loop begins quickly and slows down all the time. So far
              Message 6 of 12 , Mar 2, 2010
                John Shotsky wrote:
                > I use the loop many places, and it's an awful time penalty.

                It's not the loop as far as I can ascertain, it is the ^$GetSelection$
                and the ^!InsertText. The loop begins quickly and slows down all the
                time. So far I've decided to live with it rather than work, but if you
                want, you could try out an idea I had:

                What about reading from one file and writing to another. Of course you
                need to read and write everything but it won't need all that inserting
                any more.

                Axel
              • Don Daugherty
                ... I guess you could use 26 ^!Replace lines, e.g. ^!Replace Ka :A RWAIST ^!Replace Kb :B RWAIST etc. That s probably a lot faster than
                Message 7 of 12 , Mar 2, 2010
                  On 3/2/2010 3:03 PM, John Shotsky wrote:
                  > Yes, that's why I was trying to avoid a loop. 200,000+ line text.
                  >
                  I guess you could use 26 ^!Replace lines, e.g.
                  ^!Replace "<I>\Ka" >> :A" RWAIST
                  ^!Replace "<I>\Kb" >> :B" RWAIST
                  etc.
                  That's probably a lot faster than looping, but I haven't tried it to be
                  sure.
                  Another way would be to setup a pair of array variables containing the
                  to-be-found and the replace-by characters and loop through once for each
                  element in the arrays. That might be more flexible where an even larger
                  number of cases could be involved.
                • John Shotsky
                  Thanks, Don. I ll run this and the loop version through a timer on my big file. The I is not needed in the options, so it will ignore upper case letters
                  Message 8 of 12 , Mar 2, 2010
                    Thanks, Don.

                    I'll run this and the loop version through a timer on my 'big' file. The 'I'
                    is not needed in the options, so it will ignore upper case letters in that
                    position. I assume the colon is just a typo.



                    How would the array version look? If I wanted to lower case a letter in that
                    same position, would the array permit using two sets of characters, and
                    choosing which one was to be used at run time? I'm envisioning storing two
                    sets of characters in two variables, and setting the appropriate variable
                    active at run time. %U2L% and %L2U%, for example.



                    Regards,

                    John



                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf
                    Of Don Daugherty
                    Sent: Tuesday, March 02, 2010 2:10 PM
                    To: ntb-clips@yahoogroups.com
                    Subject: Re: [Clip] Changing case using a Replace





                    On 3/2/2010 3:03 PM, John Shotsky wrote:
                    > Yes, that's why I was trying to avoid a loop. 200,000+ line text.
                    >
                    I guess you could use 26 ^!Replace lines, e.g.
                    ^!Replace "<I>\Ka" >> :A" RWAIST
                    ^!Replace "<I>\Kb" >> :B" RWAIST
                    etc.
                    That's probably a lot faster than looping, but I haven't tried it to be
                    sure.
                    Another way would be to setup a pair of array variables containing the
                    to-be-found and the replace-by characters and loop through once for each
                    element in the arrays. That might be more flexible where an even larger
                    number of cases could be involved.





                    [Non-text portions of this message have been removed]
                  • John Shotsky
                    Thanks, Sheri, I ran this on 100,000 lines that all needed to be changed, and it took about 2 seconds, even when z was the letter to be found. Very nice. I
                    Message 9 of 12 , Mar 2, 2010
                      Thanks, Sheri,



                      I ran this on 100,000 lines that all needed to be changed, and it took about
                      2 seconds, even when 'z' was the letter to be found. Very nice.



                      I don't use PowerPro because I have a group of users that use my clips, and
                      don't want to force them to install it to run my clips. Perhaps a future
                      version of NoteTab will pick up that feature.



                      Regards,

                      John



                      From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf
                      Of Sheri
                      Sent: Tuesday, March 02, 2010 1:53 PM
                      To: ntb-clips@yahoogroups.com
                      Subject: Re: [Clip] Changing case using a Replace





                      --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , Axel
                      Berger <Axel-Berger@...> wrote:
                      >
                      > John Shotsky wrote:
                      > > regardless of what word it is.
                      >

                      [snip]

                      > ^!InsertText ^$StrUpper("^$GetSelection$")$
                      > ^!Goto loop
                      > :clean
                      >
                      > This is a construct I use quite often. On big texts in the
                      > thousands of lines InsertText becomes extremely slow.

                      Another solution invokes 26 ^!Replace-all's:

                      H="singlecharup"
                      ^!Set %finddec%=96
                      :loop
                      ^!Inc %finddec%
                      ^!If ^%finddec%>122 Out
                      ^!Set %findchar%=^$dectochar(^%finddec%)$
                      ^!Set %replchar%=^$DecToChar(^$Calc(^%finddec%-32)$)$
                      ^!Replace "^<I>\K^%findchar%" >> "^%replchar%" RAWS
                      ^!Goto loop
                      :Out

                      NoteTab lets you reproduce (but not transform) the whole match ($0) and/or
                      substrings ($1, etc.) as part of the replacement text. If above is not fast
                      enough, you can call another script or utility from inside your clip. I like
                      Powerpro because it uses the same PCRE version as NoteTab, but has
                      case-transforming capability in its replace-all equivalent. Some examples
                      can be found in the archives.

                      Regards,
                      Sheri





                      [Non-text portions of this message have been removed]
                    • Sheri
                      ... Not likely. Regards, Sheri
                      Message 10 of 12 , Mar 3, 2010
                        On 3/2/2010 5:45 PM, John Shotsky wrote:
                        > Perhaps a future
                        > version of NoteTab will pick up that feature.
                        >

                        Not likely.

                        <http://www.freelists.org/post/yunqa/Converting-upper-case-strings-to-lower-case-with-regular-expression,3>

                        Regards,
                        Sheri
                      • Don Daugherty
                        ... Definitely a TYPO ... See if this is what you mean: ^!SetDebug On ^!SetArray %SetA%= A ; B ; C ; D ; Etc. ^!SetArray %SetB%= a ; b ; c ; d ; etc. ^!Info
                        Message 11 of 12 , Mar 3, 2010
                          On 3/2/2010 4:36 PM, John Shotsky wrote:
                          > Thanks, Don.
                          > I assume the colon is just a typo.
                          >
                          Definitely a TYPO
                          > How would the array version look? If I wanted to lower case a letter in that
                          > same position, would the array permit using two sets of characters, and
                          > choosing which one was to be used at run time? I'm envisioning storing two
                          > sets of characters in two variables, and setting the appropriate variable
                          > active at run time. %U2L% and %L2U%, for example.
                          >
                          See if this is what you mean:
                          ^!SetDebug On
                          ^!SetArray %SetA%="A";"B";"C";"D";"Etc."
                          ^!SetArray %SetB%="a";"b";"c";"d";"etc."
                          ^!Info SetA=^%SetA%^%NL%SetB=^%SetB%^%NL%
                          ; A long line begins
                          ^!Set %Choice%=^?{(T=C)Select Look4-Change2 choice==_"1: Look4 ^%SetA%,
                          ChangeTo ^%SetB%"|"2: Look4 ^%SetB%, Change2 ^%SetA%"}
                          ; The long line ends; in email it looks like two!
                          ^!Set %Choice%=^$StrCopyLeft("^%Choice%";1)$
                          ^!Info Choice=^%Choice%
                          ^!If ^%Choice%=1 ^!SetArray %LookFor%=^%SetA%; %ChangeTo%=^%SetB%
                          ^!If ^%Choice%=2 ^!SetArray %LookFor%=^%SetB%; %ChangeTo%=^%SetA%
                          ^!Info
                          SetA=^%SetA%^%NL%SetB=^%SetB%^%NL%LooK4=^%LookFor%^%NL%Change2=^%ChangeTo%
                          ^!Set %N%=0
                          :NextCase
                          ^!Inc %N%
                          ^!Replace "<I>\K^%LookFor^%N%%" >> "^%ChangeTo^%N%%" RWAS
                          ^!If ^%N%<^%LookFor0% NextCase

                          Note: The long line broken by email wouldn't be very user friendly in
                          the practical case involving 26 values; ^%SetA% and ^%SetB% would have
                          to be changed to the words SetA and SetB and you would have to
                          remember, from the previous Info display, what they represent.when you
                          make your choice.
                        Your message has been successfully submitted and would be delivered to recipients shortly.