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

need: clip to selectively replace a character in selected section

Expand Messages
  • Don Passenger
    Coding in perl, when you do a print statement, you often get s within s, and to conteract that you need to preceed the inner quotes with a backslash, so
    Message 1 of 5 , Apr 30 7:40 AM
    View Source
    • 0 Attachment
      Coding in perl, when you do a print statement, you often get ""'s within ""'s, and to conteract that you need to preceed the inner quotes with a backslash, so a line would start like this:

      print "<font face="arial" color="red">red arial output</font>";

      and need to become
      print "<font face=\"arial\" color=\"red\">red arial output</font>";

      The outside quotes aren't preceded with the backslash and all inner quotes are.

      So in layman's terms, I need to find all incidents of " except the first and last in a selected portion of text and replace them with \"

      I have tried hunting around a bit and have not found the answer yet....so in the hope someone has something similiar to get me rolling,

      please help.


      ---
      Don Passenger
      Personal Page: http://www.iserv.net/~dpasseng
      Court Page: http://www.grand-rapids.mi.us/~dpasseng/grdc


      [Non-text portions of this message have been removed]
    • Wayne VanWeerthuizen
      ... If you can, you should use Perl s qq{ } syntax for quoting strings that contain quotes. To replace the internal quotes try, in Perl: 1 while
      Message 2 of 5 , Apr 30 9:07 AM
      View Source
      • 0 Attachment
        "Don Passenger" <dpasseng@...> wrote:
        >Coding in perl, when you do a print statement, you often get ""'s within ""'s, and to conteract that you need to preceed the inner quotes with a backslash, so a line would start like this:
        >
        >print "<font face="arial" color="red">red arial output</font>";
        >
        >and need to become
        >print "<font face=\"arial\" color=\"red\">red arial output</font>";
        >
        >The outside quotes aren't preceded with the backslash and all inner quotes are.
        >
        >So in layman's terms, I need to find all incidents of " except the first and last in a selected portion of text and replace them with \"
        >
        >I have tried hunting around a bit and have not found the answer yet....so in the hope someone has something similiar to get me rolling,
        >
        >please help.
        >

        If you can, you should use Perl's qq{ } syntax for quoting strings that contain quotes.

        To replace the internal quotes try, in Perl:

        1 while s{($[^"]*"[^"]*)"(.*"[^"]*^)}{\1\\"\2};

        --
        Wayne M. VanWeerthuizen
        Homepage: http://landru.myhome.net/wayne
      • Jody
        Hi Don, ... This works with the example given above. It does the whole document starting at the cursor position. Take out the loop if you only want one line
        Message 3 of 5 , Apr 30 10:29 AM
        View Source
        • 0 Attachment
          Hi Don,

          > Coding in perl, when you do a print statement, you often get
          > ""'s within ""'s, and to conteract that you need to preceed the
          > inner quotes with a backslash, so a line would start like this:
          >
          > print "<font face="arial" color="red">red arial output</font>";
          >
          > and need to become print "<font face=\"arial\" color=\"red\"red
          > arial output</font";

          > So in layman's terms, I need to find all incidents of " except
          > the first and last in a selected portion of text and replace
          > them with \"

          This works with the example given above. It does the whole
          document starting at the cursor position. Take out the loop if
          you only want one line done, place the cursor on column one or
          anywhere above the "print "" line, and click on the Clip.

          I don't perl, so this does not come with a guarantee. ;)

          <--- Copy below this line --->
          H=\PerlTags
          ; Last Updated 04/30/2000, Sojourner@..., jody
          ^!SetScreenUpdate Off

          :Loop
          ^!Find "print "" SI
          ^!IfError End
          ^!Find "="" S
          ^!Select HTMLTag
          ^!IfError End
          ^$StrReplace(""";"\"";"^$GetSelection$";0;0)$
          ^!Goto Loop

          <--- Copy above this line, right --->
          <--- click over a Library, and --->
          <--- choose "Add from Clipboard" --->

          Happy Clip'n!
          Jody

          http://www.sureword.com/notetab

          Subscribe, UnSubscribe, Options
          mailto:Ntb-Clips-Subscribe@...
          mailto:Ntb-Clips-UnSubscribe@...
          http://www.egroups.com/list/ntb-clips
        • Don Passenger
          I thank both Jody and Wayne for prompt responses. The clip sent back to me worked as promised. I then realized that sometimes the line I needed modified would
          Message 4 of 5 , Apr 30 10:10 PM
          View Source
          • 0 Attachment
            I thank both Jody and Wayne for prompt responses.
            The clip sent back to me worked as promised.
            I then realized that sometimes the line I needed modified would not contain
            an html tag (which was the method Jody used, because my example had an html
            tag).

            Jody's work permitted me to get going and write my second clip.

            This clip is at http://www.bestfoot.com/notetab/interior_quote_replace.txt
            and explained at
            http://www.bestfoot.com/notetab/interior_quote_replace.shtml

            It takes one line of text (the line your cursor is in) and does the
            following:
            1. finds the first and last quote in the line
            2. highlights all text inside the quotes, including all interior quotes
            3. replaces all interior quotes with a backslash and quote

            This is important for working in perl (I often code perl to generate html
            output), but I see significant other possibilities for the process.

            Please forward any comments.

            ---
            Don Passenger
            Personal Page: http://www.iserv.net/~dpasseng
            Court Page: http://www.grand-rapids.mi.us/~dpasseng/grdc

            > <--- Copy below this line --->
            > H=\PerlTags
            > ; Last Updated 04/30/2000, Sojourner@..., jody
            > ^!SetScreenUpdate Off
            >
            > :Loop
            > ^!Find "print "" SI
            > ^!IfError End
            > ^!Find "="" S
            > ^!Select HTMLTag
            > ^!IfError End
            > ^$StrReplace(""";"\"";"^$GetSelection$";0;0)$
            > ^!Goto Loop
            >
            > <--- Copy above this line, right --->
            > <--- click over a Library, and --->
            > <--- choose "Add from Clipboard" --->
            >
            > Happy Clip'n!
            >
          • Wayne VanWeerthuizen
            ... Well, your Perl code will then be infected with what is called, leaning toothpick syndrome . Cures do exist for it. Which of the following examples is
            Message 5 of 5 , May 1, 2000
            View Source
            • 0 Attachment
              "Don Passenger" <dpasseng@...> wrote:

              >It takes one line of text (the line your cursor is in) and does the
              >following:
              >1. finds the first and last quote in the line
              >2. highlights all text inside the quotes, including all interior quotes
              >3. replaces all interior quotes with a backslash and quote
              >
              >This is important for working in perl (I often code perl to generate html
              >output), but I see significant other possibilities for the process.

              Well, your Perl code will then be infected with what is called,
              "leaning toothpick syndrome". Cures do exist for it.


              Which of the following examples is easier to read?


              print "<font face=\"arial\" color=\"red\">red arial output</font>";

              print qq{<font face="arial" color="red">red arial output</font>};


              Both do the same thing, assuming you are using Perl 5 or better,
              which most people are, as it's been out for a long time.










              --
              Wayne M. VanWeerthuizen
              Homepage: http://landru.myhome.net/wayne
            Your message has been successfully submitted and would be delivered to recipients shortly.