23879Re: [Clip] Re: alphanumeric character transcoding, by ones and pairs
- Jun 13, 2013Flo,
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.
Note above \ character has to be doubled for this to work.
^!If ^%i% > ^%Charpair0% Out
^!Replace "(?<!\|)^%Search%" >> "|^%ReplaceWith%" WARS
^!Replace "|" >> "" WATS
This only partly works. Some of the second characters in the two
character digraphs can change a second time.
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
On 14/06/2013 6:38 AM, flo.gehrke wrote:
> --- In firstname.lastname@example.org <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
> ^!Inc %i%
> ^!If ^%i% > ^%Char0% Out
> ^!Set %Search%=^%Char^%i%%
> ^!Inc %i%
> ^!Set %ReplaceWith%=^%Char^%i%%
> ^!Replace "(?<!\|)^%Search%" >> "|^%ReplaceWith%" WARS
> ^!Goto Loop
> ^!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...
[Non-text portions of this message have been removed]
- << Previous post in topic Next post in topic >>