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

HTML to ANSI

Expand Messages
  • Axel Berger
    It seems I m going senile. I m trying in vain to convert – to the result of ^$DecToChar(150)$. (150 is just an example, it should work for any ANSI
    Message 1 of 4 , May 12, 2014
    • 0 Attachment
      It seems I'm going senile.

      I'm trying in vain to convert – to the result of ^$DecToChar(150)$.
      (150 is just an example, it should work for any ANSI character.)

      While

      ^!Set %Content%=^$StrReplace("&#(\d+);";"($1)";"^%Content%";RAI)$

      works,

      ^!Set
      %Content%=^$StrReplace("&#(\d+);";"^$DecToChar($1)$";"^%Content%";RAI)$

      doesn't. I can't even think of a solution with looping, though one without
      would be highly preferred.

      Danke
      Axel
    • flo.gehrke
      ... In #2, $1 is a RegEx metacharacter that you can t use as an argument in the string function ^$DecToChar . Instead of interpreting it as a backreference,
      Message 2 of 4 , May 13, 2014
      • 0 Attachment
        ---In ntb-clips@yahoogroups.com, <Axel@...> wrote :

        > I'm trying in vain to convert – to the result of ^$DecToChar(150)$.
        > (150 is just an example, it should work for any ANSI character.)
        >
        > While
        >
        > ^!Set %Content%=^$StrReplace("&#(\d+);";"($1)";"^%Content%";RAI)$
        >
        > works,
        >
        > ^!Set
        > %Content%=^$StrReplace("&#
        > (\d+);";"^$DecToChar($1)$";"^%Content%";RAI)$
        >
        > doesn't. I can't even think of a solution with looping, though one
        > without would be highly preferred.

        In #2, '$1' is a RegEx metacharacter that you can't use as an argument in the string function '^$DecToChar'. Instead of interpreting it as a backreference, NT tries to evaluate '$1' as a decimal value - with no correct result, of course.

        It works with a variable...

        ^!Set %Content%=&#150;
        ^!Set %Dec%=^$StrReplace("[&#;]";"";"^%Content%";RA)$
        ^!Set %Content%=^$DecToChar(^%Dec%)$

        and returns the En dash (decimal 150).

        Regards,
        Flo
         
      • flo.gehrke
        ... ...or even shorter, if you like... ^!Set %Content%=– ^!Set %Content%=^$DecToChar(^$StrReplace( [&#;] ; ; ^%Content% ;RA)$)$ Regards, Flo
        Message 3 of 4 , May 13, 2014
        • 0 Attachment
          > It works with a variable...
          >
          > ^!Set %Content%=&#150;
          > ^!Set %Dec%=^$StrReplace("[&#;]";"";"^%Content%";RA)$
          > ^!Set %Content%=^$DecToChar(^%Dec%)$

          ...or even shorter, if you like...

          ^!Set %Content%=&#150;
          ^!Set %Content%=^$DecToChar(^$StrReplace("[&#;]";"";"^%Content%";RA)$)$

          Regards,
          Flo
           
        • Axel Berger
          ... Thanks, that does it. My senility must be really kicking in now, that I didn t see that myself. Only problem now is the necessity for looping. ... ^!Find
          Message 4 of 4 , May 14, 2014
          • 0 Attachment
            "flo.gehrke@... [ntb-clips]" wrote:
            > It works with a variable...
            > ^!Set %Content%=–
            > ^!Set %Content%=^$DecToChar(^$StrReplace("[&#;]";"";"^%Content%";RA)$)$

            Thanks, that does it. My senility must be really kicking in now, that I
            didn't see that myself. Only problem now is the necessity for looping.

            :loop
            ^!Find "&#\d{3};" RSTI
            ^!IfError doneloop
            ^!Set %Content%=^$GetSelection$
            ^!InsertText ^$DecToChar(^$StrReplace("[&#;]";"";"^%Content%";RA)$)$
            ^!Goto loop
            :doneloop

            That results in extra effort to make it do the replacement not in the whole
            text but limted to a selected block. It's easy to begin at the block start,
            but not as easy to end at it's end.

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