Repeat 'replace all' until 'Search string not found' occurs

Repeat 'replace all' until 'Search string not found' occurs

2
NewbieNewbie
2

    Jan 12, 2007#1

    Is it possible to repeat a 'replace all' untill 'Search string not found' occurs? (Macro?) And indicate a max number of iterations. (to avoid infinite loops)

    206
    MasterMaster
    206

      Jan 12, 2007#2

      This basic structure?

      Loop
      Find "find string"
      IfNotFound
      ExitLoop
      EndIf
      Replace "replace string"
      EndLoop
      Software For Metalworking
      http://closetolerancesoftware.com

      6,675585
      Grand MasterGrand Master
      6,675585

        Re: Repeat 'replace all' until 'Search string not found' occurs

        Jan 12, 2007#3

        Hi mrainey56!

        Your code will not be compiled by UltraEdit because a Replace command can be only immediately after a Find command. But following will work:

        Loop x
        Find "find string"
        Replace All "replace string"
        IfNotFound
        ExitLoop
        EndIf
        EndLoop

        I use this very often in my macros. Specify for x the maximum number of iterations. But most Replace All must be executed only once. My macros to delete all blank lines at Deleting blank lines using Perl regular expressions shows an exception where a Replace All in a Loop is really needed.

        Just for your info: As DaveS detected, every Find in a macro is in real a Find with Replace with identical search and replace string. You can see that if you view a macro file in hex edit mode which contains only 1 Find but the find string is twice in the file. So IfFound and IfNotFound can be also used immediately after a Replace command because internally a Find only is in real also a Find with Replace.
        Best regards from an UC/UE/UES for Windows user from Austria

        2
        NewbieNewbie
        2

          Jan 12, 2007#4

          Guys,

          thank you very much. Works fine!

          But, regarding the speed at which you have replied with these answers (approx. 2 hours), one word: Amazing.

          cu

          206
          MasterMaster
          206

            Jan 12, 2007#5

            Thanks for the correction Mofi. That's what I get for not testing!
            Software For Metalworking
            http://closetolerancesoftware.com