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

23879Re: [Clip] Re: alphanumeric character transcoding, by ones and pairs

Expand Messages
  • Ian NTnerd
    Jun 13, 2013
    • 0 Attachment
      Flo,

      Still has bugs see bottom.

      Thanks for helping me learn more RE. Negative look behind.

      I'd simplify the array by putting it in a separate clip each pair on a
      new line and each pair separated by a tab space. That way the data is
      separated from the clip and much easier to maintain. Note this email has
      changed the tab to multiple spaces so it needs to be changed to work.
      H="_list"
      bJ bS
      dD 'f
      kY uF
      KY cF
      mD rf
      mJ rS
      pJ yS
      PJ zS
      SJ pS
      sJ qS
      a g
      A H
      b b
      B R
      c C
      d '
      E h
      e J
      F .
      f m
      g i
      h [
      H o
      I >
      i X
      j *
      J S
      K c
      k u
      L s
      l v
      m r
      n e
      o D
      O d
      p y
      P z
      q n
      r &
      S p
      s q
      t w
      T x
      u k
      v l
      w 0
      W G
      X {
      x t
      y ,
      Y F
      z ±S
      : ;
      \\ -

      Note above \ character has to be doubled for this to work.

      H="transcode"
      ^!SetListDelimiter ^p
      ^!SetArray %Charpair%=^$GetClipText("list")$
      ^!Set %i%=0

      :Loop

      ^!Inc %i%

      ^!If ^%i% > ^%Charpair0% Out
      ^!SetListDelimiter ^T
      ^!SetArray %pair%=^%Charpair^%i%%
      ^!Set %Search%=^%pair1%
      ;^!Inc %i%
      ^!Set %ReplaceWith%=^%pair2%
      ^!Replace "(?<!\|)^%Search%" >> "|^%ReplaceWith%" WARS
      ^!Goto Loop

      :Out
      ^!Replace "|" >> "" WATS


      This only partly works. Some of the second characters in the two
      character digraphs can change a second time.

      Data
      Start line
      lABTAkvFHWkolaKELdAFqalanWElacO:laKv:sE:muIsE:sFlanOlapLUB
      transformed line
      vHRxHul.oGuDvgchs'H.ngvgeGhvgCd;vgcl;qh;rk>qh;q.vgedvgysUR
      Wanted line
      vhRxhul.oGhuDvgcHs'h.ngvgEGHvgCd;vgcl;qH;rk>qH;q.vgeDvgysKR


      So I think this is a fail. Changing the order may fix the problem but it
      may introduce new problems. It really needs to be processed as a string.

      But there may be some data inconsistency between the supplied changes
      and the two strings. i.e the second letter H or h

      Ian

      On 14/06/2013 6:38 AM, flo.gehrke wrote:
      >
      > --- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com>,
      > "rickah" <richolland@...> wrote:
      > >
      > > (...) I want create a clip that would re-write the characters
      > > in this first string to exactly match the characters in the
      > > second string.
      > >
      > > 1: lABTAkvFHWkolaKELdAFqalanWElacO:laKv:sE:muIsE:sFlanOlapLUB
      > > 2: vhRxhul.oGhuDvgcHs'h.ngvgEGHvgCd;vgcl;qH;rk>qH;q.vgeDvgysKR
      > > (...)
      > > Making the following list is as far as I got.
      > > --list--
      > > ^!Replace "bJ" >> "bS"
      > > ^!Replace "dD" >> "'f"
      > > etc
      >
      > This is no complete solution but just a basic idea:
      >
      > Example: In order to replace 'ABdEHhdDSJ' with 'HR'ho[fpS' try the
      > following clip:
      >
      > ^!SetArray %Char%=A;H;B;R;E;h;H;o;h;[;dD;f;SJ;pS;d;'
      > ^!Set %i%=0
      >
      > :Loop
      > ^!Inc %i%
      > ^!If ^%i% > ^%Char0% Out
      > ^!Set %Search%=^%Char^%i%%
      > ^!Inc %i%
      > ^!Set %ReplaceWith%=^%Char^%i%%
      > ^!Replace "(?<!\|)^%Search%" >> "|^%ReplaceWith%" WARS
      > ^!Goto Loop
      >
      > :Out
      > ^!Replace "|" >> "" WATS
      >
      > In array %Char%, you see a sequence where each character is followed
      > by the character it has to be replaced with. Note: In the array, a
      > string like 'd' must follow 'dD'.
      >
      > The point is not to replace a 'h' that replaced an 'E' again with '['.
      > To prevent this, each character that has been replaced already is
      > protected with '|'. So '|h' won't get replaced with [' again. This is
      > achieved by the Negative Lookbehind '(?<!\|)'.
      >
      > Probably, there are more issues in this but I hope it might be useful
      > as a first approach...
      >
      > Regards,
      > Flo
      >
      >



      [Non-text portions of this message have been removed]
    • Show all 19 messages in this topic