Find and replace in selected text

Find and replace in selected text

4
NewbieNewbie
4

    Jun 15, 2007#1

    I tested jorrasdk solution: it works well. Thanks jorrasdk . This solution is right if you want "find and replace all". Now consider that I've one or more part of the file in which I don't want to replace "%^(*^);*$" with "^1"

    Here is an example of the text file:

    .PROGRAM goofy()
    la la ; bla bla
    alb alb
    .END
    .PROGRAM micky()
    ; ping ping
    pong pong
    .END

    and I want to change only the part of the text file between PROGRAM goofy() and .END that follows, while the part of the text between
    .PROGRAM micky() and .END that follows must be unchanged.
    The outcome must be:

    .PROGRAM goofy()
    la la
    alb alb
    .END
    .PROGRAM micky()
    ; ping ping
    pong pong
    .END

    To determine which part of the text file must be changed and which not is it possible to open a text file (in the same folder of the file to deal with) with the list of the parts (programs) to let unchanged? Something like this:

    goofy

    After having opened and read the list of parts (Programs) to let unchanged it could be possible to assign each name of program to an array variable and scan the entire text file, from the top to the botton, and change or not individual part (program) of the file. Is it possible?

    Could someone help me?
    PS. I now that this could be considered a repost. Sorry for this.
    mosca

    262
    MasterMaster
    262

      Jun 15, 2007#2

      I meant to post a suggestion for a solution. But the path I choose for a solution included

      UltraEdit.activeDocument.findReplace.selectText=true;
      UltraEdit.activeDocument.findReplace.replace("%^(*^);*$","^1");

      and selectText/replace seems to be broken in UE13.10. IDM Support confirmed this. I selected functions not on an "ignore list" and the tried to perform the replace above.

      And I haven't had the time to seek another solution not depending on findReplace.selectText. I may get back with the solution if the selectText issue is fixed in a hotfix soon.

      Meanwhile others are welcome to suggest other solutions.

      6,681583
      Grand MasterGrand Master
      6,681583

        Re: Find and replace

        Jun 15, 2007#3

        I think your problem here is, that script property selectText is the the equivalent for macro code:

        Find "..."
        Replace All SelectText "..."


        which means replace all in selected text and requires also

        UltraEdit.activeDocument.findReplace.replaceAll=true;

        In the macro environment there is also:

        Find Select "..."

        which means find the search string and select everything from current cursor position to end of found string or expand existing selection to end of found string. There is no equivalent for this function in the scripting environment as far as I know.

          Re: Find and replace

          Jun 15, 2007#4

          Without testing it, here is a macro solution for this job. The macro property Continue if a Find with Replace not found must be checked for this macro.

          InsertMode
          ColumnModeOff
          HexOff
          UnixReOff
          Top
          Loop
          Find MatchCase ".PROGRAM goofy()"
          IfNotFound
          ExitLoop
          EndIf
          Find Select ".END"
          Find RegExp "%^(*^);*$"
          Replace All SelectText "^1"
          EndSelect
          Key LEFT ARROW
          Find MatchCase Up ".PROGRAM goofy()"
          Key LEFT ARROW
          EndLoop

          Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
          Best regards from an UC/UE/UES for Windows user from Austria

          262
          MasterMaster
          262

            Jun 15, 2007#5

            Hi Mofi
            Mofi wrote:I think your problem here is, that script property selectText is the the equivalent for macro code:

            Find "..."
            Replace All SelectText "..."
            You're probably right that selectText is taking after the macro equivalent. But what really makes sense in the scripting is that it implements the replace dialogs "Replace where: Selected text".

            I sent this short script to IDM Support:

            Code: Select all

            // AAA
            // AAA
            // ====================
            // AAA
            // AAA
            // ====================
            UltraEdit.ueReOn();
            UltraEdit.activeDocument.top();
            UltraEdit.activeDocument.gotoLineSelect(3,1);
            UltraEdit.activeDocument.findReplace.selectText=true;
            UltraEdit.activeDocument.findReplace.replaceAll=false;
            UltraEdit.activeDocument.findReplace.replace("AAA","ZZZ");
            
            and explained that when the script is run upon itself, I expect only the first "AAA"' to be replaced with "ZZZ" (or the first two if replaceAll=true). But all "AAA"'s are replaced - both in selected text and non-selected text. replaceAll is ignored (tested with both true and false).
            IDM Support aggreed that this is an error.