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

StrReplace

Expand Messages
  • Axel Berger
    There used to be the problem that ^!Replace could not use functions and ^$StrReplace()$ could not use Regex. The latter seems to be fixed, except for one
    Message 1 of 13 , Nov 28, 2012
    View Source
    • 0 Attachment
      There used to be the problem that ^!Replace could not use functions and
      ^$StrReplace()$ could not use Regex. The latter seems to be fixed,
      except for one thing:

      How do I use the found string? $1 does not seem to work. The following
      should convert Russian characters from cp-1251 to Unicode-entities (one
      line):

      ^!InsertText
      ^$StrReplace("[\xC0-\xF0]";"&#^$Calc(848+^$CharToDec($1)$;0)$;";"^$GetSelection$";RA)$

      It doesn't, everything is 848.

      How can I do it?

      Danke
      Axel

      --
      Dipl.-Ing. F. Axel Berger Tel: +49/ 2174/ 7439 07
      Johann-Häck-Str. 14 Fax: +49/ 2174/ 7439 68
      D-51519 Odenthal-Heide eMail: Axel-Berger@...
      Deutschland (Germany) http://berger-odenthal.de
    • hsavage
      ... Axel, I m way behind with regex but in your case you may need to try the NoteTab fixed variable ^%Dollar%. ^$CharToDec(^%Dollar%1)$;0)$ --
      Message 2 of 13 , Nov 28, 2012
      View Source
      • 0 Attachment
        On 11/28/2012 4:26 PM, Axel Berger wrote:
        > There used to be the problem that ^!Replace could not use functions and
        > ^$StrReplace()$ could not use Regex. The latter seems to be fixed,
        > except for one thing:
        >
        > How do I use the found string? $1 does not seem to work. The following
        > should convert Russian characters from cp-1251 to Unicode-entities (one
        > line):
        >
        > ^!InsertText
        > ^$StrReplace("[\xC0-\xF0]";"&#^$Calc(848+^$CharToDec($1)$;0)$;";"^$GetSelection$";RA)$
        >
        > It doesn't, everything is 848.
        >
        > How can I do it?
        >
        > Danke
        > Axel

        Axel,

        I'm way behind with regex but in your case you may need to try the
        NoteTab fixed variable ^%Dollar%.

        ^$CharToDec(^%Dollar%1)$;0)$


        --
        ···············································
        ¤. JD#...333 - ¤. SL...1054 - 12.11.28~12.28.03

        . On A Fence: Salesmen Welcome. Dog Food Is Expensive.

        EUR hrs EUR hsavage EUR pobox EUR com



        [Non-text portions of this message have been removed]
      • Axel Berger
        ... Doesn t help. In my UTF converter, where I expected only few such characters loosely scattered through the text I looped through individual chars. Here,
        Message 3 of 13 , Nov 29, 2012
        View Source
        • 0 Attachment
          hsavage wrote:
          > fixed variable ^%Dollar%.
          > ^$CharToDec(^%Dollar%1)$;0)$

          Doesn't help. In my UTF converter, where I expected only few such
          characters loosely scattered through the text I looped through
          individual chars. Here, where it is a compact block of all Russian, I
          hoped to avoid a second inner loop.

          Axel
        • Axel Berger
          ... Addendum: I can t use an inner loop. ^!Find something H selects the found item and destroys the outer selection. ^!Replace old new H doesn t allow
          Message 4 of 13 , Nov 29, 2012
          View Source
          • 0 Attachment
            Axel Berger wrote:
            > I hoped to avoid a second inner loop.

            Addendum: I can't use an inner loop.

            ^!Find "something" H

            selects the found item and destroys the outer selection.

            ^!Replace "old" >> "new" H

            doesn't allow a function in "new".

            I might go to the length of doing

            ^!Replace "old" >> "#markrussian#old#endmark#" H

            and run a second loop over the whole text without changing non-russian
            upper characters. This is becoming a lot of hassle for a simple task.

            Axel
          • flo.gehrke
            ... ^$CharToDec()$ is a conventional string function that can t deal with a RegEx metacharacter. So $1 isn t interpreted as a back reference here but as a
            Message 5 of 13 , Nov 29, 2012
            View Source
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
              >
              > How do I use the found string? $1 does not seem to work.

              '^$CharToDec()$ is a conventional string function that can't deal with a RegEx metacharacter. So '$1' isn't interpreted as a back reference here but as a literal:

              ^!Info ^$CharToDec($1)$ --> 36. i.e. the decimal value of '$' (1 is ignored)

              Maybe you could resolve it with something like...

              ^!Find "[\xC0-\xF0]" RS
              ^!Set %Char%="&#^$Calc(848+^$CharToDec(^$GetSelection$)$)$;"
              ^!InsertText ^$StrReplace("^$GetSelection$";"^%Char%";"^$GetSelection$";RA)$

              Also note: '[\xC0-\xF0]' wouldn't work as a substring unless it written in parentheses. Example:

              ^!Info ^$StrReplace("(apple)\x20tree";"$1\x20pie";"apple tree";R)$ --> apple pie

              Regards,
              Flo
            • flo.gehrke
              ... Or just... ^!Find [ xC0- xF0] R ^!Set %Char%= &#^$Calc(848+^$CharToDec(^$GetSelection$)$)$; ^!Replace ^$GetSelection$ ^%Char% ST Regards, Flo
              Message 6 of 13 , Nov 29, 2012
              View Source
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, "flo.gehrke" <flo.gehrke@...> wrote:
                >
                > Maybe you could resolve it with something like (corrected)...
                >
                > ^!Find "[\xC0-\xF0]" RS
                > ^!Set %Char%="&#^$Calc(848+^$CharToDec(^$GetSelection$)$)$;"
                > ^!InsertText ^$StrReplace("^$GetSelection$";"^%Char%";"^$GetSelection$";R)$

                Or just...

                ^!Find "[\xC0-\xF0]" R
                ^!Set %Char%="&#^$Calc(848+^$CharToDec(^$GetSelection$)$)$;"
                ^!Replace "^$GetSelection$" >> "^%Char%" ST

                Regards,
                Flo
              • Axel Berger
                ... Yes, but it needs to be a Find H inside a selection and the first hit destroys it. I ll now use a regex ^!Replace to mark the russian letters and a second
                Message 7 of 13 , Nov 29, 2012
                View Source
                • 0 Attachment
                  "flo.gehrke" wrote:
                  > > ^!Find "[\xC0-\xF0]" RS

                  Yes, but it needs to be a Find H inside a selection and the first hit
                  destroys it. I'll now use a regex ^!Replace to mark the russian letters
                  and a second ^!Find loop to work them one by one.

                  And thanks for the other hints - I had spotted the missing parentheses
                  myself, but it did take some time.

                  Axel
                • John Shotsky
                  I often do things like this, and find it easiest to do the initial find, then use replaces within that find, then loop back to do another find. You can use
                  Message 8 of 13 , Nov 29, 2012
                  View Source
                  • 0 Attachment
                    I often do things like this, and find it easiest to do the initial find, then use replaces within that find, then loop
                    back to do another find. You can use IfError Next within a selection without breaking the selection. I also use \K and
                    (?=�) to limit the find to only the exact character strings that I want to operate on. Sometimes (?s) is also needed if
                    line breaks are involved in the find.

                    So, overall structure is this:
                    Jump 1
                    :Start
                    Find [whatever]
                    IfError End
                    Replace [whatever] >> [whatever] AHIRS0
                    IfError Next Else Skip_-1
                    [any other Replaces that are needed]
                    ^!Jump Select_End
                    GoTo Start
                    :End

                    The result is a loop within a loop without breaking the selection.

                    Regards,
                    John
                    RecipeTools Web Site: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com/

                    From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Axel Berger
                    Sent: Thursday, November 29, 2012 08:17
                    To: ntb-clips@yahoogroups.com
                    Subject: Re: [Clip] Re: StrReplace


                    "flo.gehrke" wrote:
                    > > ^!Find "[\xC0-\xF0]" RS

                    Yes, but it needs to be a Find H inside a selection and the first hit
                    destroys it. I'll now use a regex ^!Replace to mark the russian letters
                    and a second ^!Find loop to work them one by one.

                    And thanks for the other hints - I had spotted the missing parentheses
                    myself, but it did take some time.

                    Axel



                    [Non-text portions of this message have been removed]
                  • Axel Berger
                    ... That If ought to be superfluous - the A already does the same. And yes, thats exactly what I m going to do, except that with Replace I can only set a
                    Message 9 of 13 , Nov 29, 2012
                    View Source
                    • 0 Attachment
                      John Shotsky wrote:
                      > Replace [whatever] >> [whatever] AHIRS0
                      > IfError Next Else Skip_-1

                      That If ought to be superfluous - the A already does the same.

                      And yes, thats exactly what I'm going to do, except that with Replace I
                      can only set a marker, not the final thing which requires using a
                      function.
                      As ^$Function($1)$ can't be used I'll have to loop them one by one and
                      use ^$Function(^$GetSelection$)$.

                      Never mind. In most cases there won't be any Russian and then it all
                      boils down to two failed Finds, that take up no time whatever. Still,
                      Regex and functions would be very nice to have in the same Replace
                      command or function.

                      Axel
                    • Axel Berger
                      ... To finalize the thread, this is what I ve come up with and what seems to ... ^!Jump TEXT_START ... ;long line start ^!Find
                      Message 10 of 13 , Nov 30, 2012
                      View Source
                      • 0 Attachment
                        Axel Berger wrote:
                        > And yes, that's exactly what I'm going to do,

                        To finalize the thread, this is what I've come up with and what seems to
                        work fine:

                        :russian
                        ^!Jump TEXT_START
                        :russloop
                        ;long line start
                        ^!Find "(?s)^\\inputencoding\{x-cp1251(.*?)^\\inputencoding\{x-atarist"
                        HRS1
                        ;long line end
                        ;^!Continue
                        ^!IfError unicode
                        ^!Replace "([\xC0-\xFF])" >> "&#R$1;" HRAST
                        ^!Goto russloop
                        :unicode
                        ^!Jump TEXT_START
                        :uniloop
                        ^!Find "&#(R.);" RS1
                        ;^!Continue
                        ^!IfError atari
                        ;long line start
                        ^!InsertText
                        ^$Calc(848+^$CharToDec(^$StrCopyRight("^$GetSelection$";1)$)$;0)$
                        ;long line end
                        ^!Goto uniloop
                        :atari

                        Axel
                      • joy8388608
                        ... How about a set of farclip subroutines that remember the current selection and reselect the remembered selection? That would be a nice enhancement! Joy
                        Message 11 of 13 , Nov 30, 2012
                        View Source
                        • 0 Attachment
                          --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                          >
                          > "flo.gehrke" wrote:
                          > > > ^!Find "[\xC0-\xF0]" RS
                          >
                          > Yes, but it needs to be a Find H inside a selection and the first hit
                          > destroys it. I'll now use a regex ^!Replace to mark the russian letters and a second ^!Find loop to work them one by one.
                          >
                          > Axel
                          >

                          How about a set of farclip subroutines that remember the current selection and reselect the remembered selection? That would be a nice enhancement!

                          Joy
                        • flo.gehrke
                          ... Interesting solution! Maybe you could even omit marking those characters with R . Search those characters inside the selection, assign them to an array,
                          Message 12 of 13 , Dec 1, 2012
                          View Source
                          • 0 Attachment
                            --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
                            >
                            > To finalize the thread, this is what I've come up with and what
                            ; seems to work fine:
                            >
                            > :russian
                            > ^!Jump TEXT_START
                            > :russloop
                            > ;long line start
                            > ^!Find "(?s)^\\inputencoding\{x-cp1251(.*?)^\\inputencoding\{x-atarist"
                            > HRS1
                            > ;long line end
                            > ;^!Continue
                            > ^!IfError unicode
                            > ^!Replace "([\xC0-\xFF])" >> "&#R$1;" HRAST
                            > ^!Goto russloop
                            > :unicode
                            > ^!Jump TEXT_START
                            > :uniloop
                            > ^!Find "&#(R.);" RS1
                            > ;^!Continue
                            > ^!IfError atari
                            > ;long line start
                            > ^!InsertText
                            > ^$Calc(848+^$CharToDec(^$StrCopyRight("^$GetSelection$";1)$)$;0)$
                            > ;long line end
                            > ^!Goto uniloop
                            > :atari


                            Interesting solution!

                            Maybe you could even omit marking those characters with 'R'. Search those characters inside the selection, assign them to an array, and edit them one after another in the same order.

                            I don't have your data and couldn't test it. But possibly it could work as follows:


                            ^!Find "(?s)^\\inputencoding\{x-cp1251.*?^\\inputencoding\{x-atarist" WRS
                            ^!SetListDelimiter "|"
                            ^!SetArray %Char%=^$GetDocListAll("[\xC0-\xFF]";"&#$0;|")$
                            ^!Set %i%=1

                            :Loop
                            ^!Find "[\xC0-\xFF]" RS
                            ; Long line start
                            ^!InsertText ^$StrReplace(^$GetSelection$;^$Calc(848+^$CharToDec(^$GetSelection$)$)$;"^%Char^%i%%";R)$
                            ; Long line end
                            ^!Inc %i%
                            ^!If ^%i% < ^%Char0 Loop


                            Regards,
                            Flo
                          • Axel Berger
                            ... There may be more than one such foreign block and there may be more than one lnguage, Greek and Hebrew are other possibilities. That s why I needed the R
                            Message 13 of 13 , Dec 1, 2012
                            View Source
                            • 0 Attachment
                              "flo.gehrke" wrote:
                              > Maybe you could even omit marking those characters with 'R'. Search
                              > those characters inside the selection, assign them to an array, and
                              > edit them one after another in the same order.

                              There may be more than one such foreign block and there may be more than
                              one lnguage, Greek and Hebrew are other possibilities. That's why I
                              needed the R to specify Russian.

                              Axel
                            Your message has been successfully submitted and would be delivered to recipients shortly.