Usage of ^c (clipboard content) and ^s (selected text) in search and replace

Usage of ^c (clipboard content) and ^s (selected text) in search and replace

3

    Dec 09, 2004#1

    Can you use a GetString within ReplInFiles? An example:

    ReplInFiles OutputWin "c:\temp\test\" "*.html" "home" "[GetString "What do you want in here?"]"

    Thanks

    6,682583
    Grand MasterGrand Master
    6,682583

      May 07, 2006#2

      No, but with ^s (= selected text) or ^c (= clipboard content) you can do this. Example macro code:

      NewFile
      GetString "What do you want in here?"
      Clipboard 9
      SelectAll
      Copy
      EndSelect
      CloseFile NoSave
      ReplInFiles OutputWin "c:\temp\test\" "*.html" "home" "^c"
      ClearClipboard
      Clipboard 0

      A small tutorial for ^s and ^c

      ^s and ^c cannot be used with a Unix or Perl regular expression. But it can be used with an UltraEdit style regex. But the text selected or in the clipboard (any of the 10 available clipboards - see above) will be handled as regular expression string and not as normal text.

      For example the selected text x+y expressed in the search string with ^s with UltraEdit style regex enabled and Match Case also enabled is interpreted as: find a string with 1 or more occurrences of x followed by y. So it will find xy, xxy, xxxy, ... and not x+y as you maybe would expect.

      If you use ^s or ^c with a normal search (regular expression is not checked), it will be interpreted as "x+y". The text selected or in the clipboard is always interpreted as normal text in the replace string. Nevertheless, ^s and ^c can be also in the replace string not used in a Unix or Perl regex replace.

      The text selected or in the clipboard can be also a block of lines. The 1000 characters size limit of the find/replace enter fields does not exist for a text selected or held in the clipboard.

      I think, the 1000 characters limit is from the MS function WriteProfileString and GetProfileString which I think are used to save the find/replace strings in the find/replace history in the INI. ^s and ^c need only 2 bytes in the find/replace history.

      Interesting things can be done with these two special characters. For example you have a macro like that:

      IfSel
      Find MatchCase "^s"
      Replace "<a href="^s">^s</a>"
      EndIf

      This is like the following code:

      IfSel
      InsertMode
      Clipboard 9
      Cut
      "<a href=""
      Paste
      "">"
      Paste
      "</a>"
      Clipboard 0
      EndIf

      But the first macro with the single replace has some advantages:

      a) It does not need a clipboard, so your current clipboard is not changed by the macro.
      b) It is independent of insert or overstrike mode. So your current edit mode is not changed (if not hex mode).
      c) It's a single replace, so it produces only 1 undo step.

      Well, I use for this "Make URL" code a template with the template code:

      <a href="[$replace$]">[$replace$]</a>

      Templates can be used easier than macros and you can use templates also within a macro.

      Update: ^c and ^s support Unicode characters not available in system code page since UltraEdit for Windows v24.00 and UEStudio v17.00 which means full Unicode support by ^c and ^s.

      206
      MasterMaster
      206

        May 07, 2006#3

        Good stuff!