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

RE: [Clip] Changing case using a Replace

Expand Messages
  • 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 1 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 2 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 3 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.