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

Looping a search and replacement

Expand Messages
  • Patrick-Julien Germain
    Hi all, I was wondering whether it is possible to loop in a document searching for any occurrences of a given text and replacing this occurrence with another
    Message 1 of 3 , Aug 6, 2002
    • 0 Attachment
      Hi all,

      I was wondering whether it is possible to loop in a document searching for
      any occurrences of a given text and replacing this occurrence with another
      text. The problem is I cannot use the standard Find/Replace feature for the
      flwg reason:

      I want to search for all the occurrences of email addresses throughout my
      document. I want to replace each occurrence with its equivalent using html
      code for its letter; for instance, suppose the first email address is
      me@..., it will be replaced with
      me@myisp.com (in
      order to hide it from spam robots), and so forth.

      How can I write a loop searching for each occurrence and writing its
      replacement text?

      I unsuccessfully searched the Help for loop or similar items--this
      particular paragraph is meant for Sheri (=:

      Any idea or advice?

      Thanks in advance.

      Best regards.

      Patrick-Julien Germain
      pjg@...
      http://pjg.free.fr/

      http://www.oiseaubleu.org/

      http://thimote.free.fr/
    • Alan C.
      Hi Patrick, ... So, that s 1 example. But will all replacements be made with the same text as in your example or will it be a different, unique replacement
      Message 2 of 3 , Aug 6, 2002
      • 0 Attachment
        Hi Patrick,

        >I want to replace each occurrence with its equivalent using html
        >code for its letter; for instance, suppose the first email address is
        >me@..., it will be replaced with
        >me@myisp.com

        So, that's 1 example. But will all replacements be made with the same text as in your example or will it be a different, unique replacement text each time?

        >How can I write a loop searching for each occurrence and writing its
        >replacement text?

        Loop can do it. But regex might probably serve better here. Each different email address does have at least a somewhat similar pattern.

        Pattern is what regex is all about.

        If same replacement text is used each time then consider a regex with the option to replace **all occurrences in the **whole doc. options RAW and any others that you need.

        I'm not so keen on regex yet. Others on this list far exceed me on regex. If looks to you may work then you might look the help index for regex also for the replace command and its available options since regex uses the standard replace command but adds the option R for regex.

        --
        Alan.
      • silvermoonwoman2001
        ... ... Hi Patrick, Notetab clips let us goto labels, either because of a ^!Goto command or because tested conditions. The documentation entry on
        Message 3 of 3 , Aug 6, 2002
        • 0 Attachment
          --- In ntb-clips@y..., "Patrick-Julien Germain" <pjg@f...> wrote:
          <snip>

          > How can I write a loop searching for each occurrence and writing its
          > replacement text?
          >
          > I unsuccessfully searched the Help for loop or similar items--this
          > particular paragraph is meant for Sheri (=:
          >
          > Any idea or advice?
          >
          > Thanks in advance.
          >

          Hi Patrick,

          Notetab clips let us goto labels, either because of a ^!Goto command
          or because tested conditions. The documentation entry on Labels
          should be helpful.

          Meanwhile, try to learn by this example ;)

          You could add a ^!Jump Doc_Start before the :Start label; otherwise,
          it will run forward from the current cursor location until no more
          email addys are found, or until canceled.

          By the way I don't do HTML, so let me know if the attached works
          properly. I went strictly by your example, and because I read this
          forum at Yahoo, I couldn't even see the m e @ m y i s p . c o m <g>

          Regards,
          Sheri

          H="HTML ChartoDec Email Addys"
          ;08/06/2002 by Sheri Pierce
          :Start
          ^!Find "[A-Z_.-0-9]+@[A-Z_.-0-9]+" IRS
          ^!IfError End
          ;comment out the next 3 lines to avoid prompting
          ^!Set %doit%=^?{Encode All ^$GetSelection$?==_Yes|No}
          ^!IfCancel End
          ^!If ^%doit%="No" Start
          ^!Set %TarLength%=^$GetSelSize$
          ^!Set %Find%=^$GetSelection$
          ^!Set %Trans%=^%Empty%
          ^!Set %i%=0
          :LoopTarget
          ^!If ^%i%>^%TarLength% Out
          ^!Inc %i%
          ^!Append %Trans%=&#^$CharToDec(^$StrCopy("^$GetSelection$";^%i%;1)$)$;
          ^!Goto LoopTarget
          :Out
          ^!InsertSelect "^$StrDeleteRight("^%Trans%";3)$"
          ^!Set %Replace%=^$GetSelection$
          ^!Jump Select_End
          ^!Replace "^%Find%" >> "^%Replace%" AIS
          ^!Goto Start
          :End
          ^!ClearVariable %doit%
          ^!ClearVariable %TarLength%
          ^!ClearVariable %Find%
          ^!ClearVariable %Replace%
          ^!ClearVariable %Trans%
          ^!Prompt All Done
          ;end of clip
        Your message has been successfully submitted and would be delivered to recipients shortly.