Tapatalk

find selected text - delete line

find selected text - delete line

12
Basic UserBasic User
12

    Sep 20, 2005#1

    Hi there, another topic I just looked at seemed to have the basics of what I'd like to do in a macro, I've written a pseudo code explanation of what I'd like to do... any suggestsions are welcome:

    Top
    Loop
    Find "%selected text%" (Id like to search for the currently selected text, but don't see how to reference that using the Find macro command)
    IfNotFound
    ExitLoop
    EndIf
    DeleteLine
    EndLoop

    It also seems (like one of the responders to the other topic observed) that a Search & Replace is MUCH faster than a macro like this... so if there's any way to delete the entire line in a S&R operation when a selected string is found - that would be GREAT! In other words - is a macro really needed for this type of thing? A S&R 'replace all' operation is also alot nicer because you can undo what you've done in a single <CTRL+Z> keystroke as opposed to one for each individual find/delete line combination from the loop above...

    206
    MasterMaster
    206

      Sep 20, 2005#2

      The search string to find selected text is ^s

      I can't make it work as part of a larger regular expression search.

      To find and delete all lines containing a string, the general format is:

      Find What: ^.*SearchString.*\p
      Replace With: Nothing (an empty string)

      Regular Expressions must be checked - my example is for Unix-style
      Check the active style in Advanced > Configuration > Find
      Software For Metalworking
      http://closetolerancesoftware.com

      6,685587
      Grand MasterGrand Master
      6,685587

        Sep 20, 2005#3

        As mrainey56 has written ^s is the code for selected text. But you need this only for a search (+ replace) within a macro. If you have a selection and execute the replace command, the selected text is automatically inserted in the "Find What" field. You only have to expand the string now with the code mrainey56 as written for Unix style regular expression or with following code for UltraEdit style:

        Find What: %*search string*^p

        If you run this regular expression replace, you can delete all lines containing this string. However, there is one problem.

        The selected string, which is automatically used as search string during command call, should not have any character, which is interpreted as regular expression character. For example characters like *[] should not be inside the selected string. If the selected string contains such characters, you have to insert the escape character ^ for UltraEdit style or \ for Unix style before every special regular expression character.

        ^s cannot be used in a regular expression search in Unix style in the search string. This is mentioned in the help of UltraEdit at bottom of the topic about regular expressions. With UltraEdit style ^s can be used inside a regular expression search string, but you must know, that the selected string will be interpreted as regular expression and not as normal text.

        For better understanding this, I post here the important part of an email, which I have written on 2005-09-16 (3 days ago) to IDM and which was confirmed by IDM.

        -----------------------

        I noticed, that ^c and ^s are simply not working in a regular expression search with Unix style. This is already mentioned in the help of UltraEdit at bottom of the regular expression help page. So the difference is that UltraEdit supports ^c and ^s in an UltraEdit style regular expression find whereelse they are not supported in an Unix regular expression find.

        As a result of this issue, the difference about interpretation of ^s and ^c and other ^? codes should be better explained in the help. What can be used in UltraEdit style regular expression and how is it interpreted.

        You can look at my example and what was the problem for me and why I first wanted to use %^c$ in an UltraEdit style regular expression.

        The example file is Testfile.txt which has following content:

        Code: Select all

        with time
        without + with time
        with 3 octet time
        with 7 octet time
        with 3 + 7 octet time
        with time
        without + with time
        with 7 octet time
        with 3 + 7 octet time
        not used
        ;
        Strings EN;Strings DE
        with time;mit Zeit
        without + with time;ohne + mit Zeit
        with 3 octet time;mit 3 Oktett Zeit
        with 7 octet time;mit 7 Oktett Zeit
        with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
        not available;nicht verfügbar
        At top of the file it contains some strings which were collected before from an other file (content is similar to a windows resource file). Some strings are duplicate and some strings have only an identical part at end of the string. Each string is on a separate line. After these strings, there is a line, which only have a ; at column 1. This is the marker, where the collected strings where inserted before into the file. The Testfile.txt is a CSV file which has a header row followed by rows with already translated english and german strings separated by a ;.

        The macro now has to search for each string at top of the file for an 100% match in the CSV area. If a string can be found in the CSV area, the string at top of the file and all it's duplicates in the upper area can be deleted, because this string was already translated.

        Two lines demonstrates the main problem, why I wanted to use ^s inside a regular expression without interpretation of the selected string as regular expression:

        with time
        without + with time

        String "with time" is identical to a part of string "without + with time". The macro has to make sure not to remove strings, which are part of other strings. The second problem is the + character, which is a regular expression character.

        Macro which I first thought should do the job with regular expressions in UltraEdit style.

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Clipboard 9
        Top
        Loop
        IfCharIs ";"
        ExitLoop
        EndIf
        StartSelect
        Key END
        Copy
        EndSelect
        Find RegExp "%^c;"
        IfNotFound
        Key HOME
        "!NEW="
        Key END
        ";"
        Key HOME
        Key DOWN ARROW
        Else
        Top
        Find RegExp "%^c$"
        Key HOME
        Find RegExp "%^c^p"
        Replace All ""
        EndIf
        EndLoop
        DeleteLine
        ClearClipboard
        Clipboard 0
        Top


        The result of this macro at Testfile.txt is:

        Code: Select all

        !NEW=without + with time;                          <- WRONG RESULT !!!
        !NEW=with 3 + 7 octet time;                        <- WRONG RESULT !!!
        !NEW=without + with time;                          <- WRONG RESULT !!!
        !NEW=with 3 + 7 octet time;                        <- WRONG RESULT !!!
        !NEW=not used;
        Strings EN;Strings DE
        with time;mit Zeit
        without + with time;ohne + mit Zeit
        with 3 octet time;mit 3 Oktett Zeit
        with 7 octet time;mit 7 Oktett Zeit
        with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
        not available;nicht verfügbar
        The wrong results are caused by the interpretation of the + character as regular expression character.

        Here is the solution I now use. It has the advantage, that also translated strings which where not present anymore in the "resource" file are marked in the CSV file after macro execution.

        InsertMode
        ColumnModeOff
        HexOff
        UnixReOff
        Clipboard 9
        Top
        Find RegExp "%;"
        Key HOME
        SelectToTop
        Find RegExp "%^(*^)$"
        Replace All SelectText ">>^1<<"
        EndSelect
        Top
        Find RegExp "%;"
        Key DOWN ARROW
        Key DOWN ARROW
        SelectToBottom
        Find RegExp "%^(*^)$"
        Replace All "!DEL=^1"
        EndSelect
        Top
        Loop
        IfCharIs ";"
        ExitLoop
        EndIf
        Key RIGHT ARROW
        Key RIGHT ARROW
        StartSelect
        Key END
        Key LEFT ARROW
        Key LEFT ARROW
        Copy
        EndSelect
        Find "!DEL=^c;"
        IfNotFound
        Key HOME
        Key DEL
        Key DEL
        "!NEW="
        Key END
        Key BACKSPACE
        Key BACKSPACE
        ";"
        Key HOME
        Key DOWN ARROW
        Else
        Key HOME
        Find "!DEL="
        Delete
        Top
        Find ">>^c<<"
        Key HOME
        EndIf
        Find ">>^c<<^p"
        Replace All ""
        EndLoop
        DeleteLine
        ClearClipboard
        Clipboard 0
        Top


        The result of this macro is what I want:

        Code: Select all

        !NEW=not used;
        Strings EN;Strings DE
        with time;mit Zeit
        without + with time;ohne + mit Zeit
        with 3 octet time;mit 3 Oktett Zeit
        with 7 octet time;mit 7 Oktett Zeit
        with 3 + 7 octet time;mit 3 + 7 Oktett Zeit
        !DEL=not available;nicht verfügbar
        Best regards from an UC/UE/UES for Windows user from Austria

        206
        MasterMaster
        206

          Sep 20, 2005#4

          Hi Mofi,

          Thanks for the detailed info, very useful.


          Mike
          Software For Metalworking
          http://closetolerancesoftware.com

          3
          NewbieNewbie
          3

            Jul 06, 2006#5

            This was very helpful, thank you =)