Inserting a string or tag multiple times at marked positions at once

Help with writing and running scripts

Inserting a string or tag multiple times at marked positions at once

Postby Mofi » Tue Mar 16, 2010 7:38 am

In some other editors it is possible to mark positions in a file and then type a text which is inserted at all marked positions at once. Sometimes it is even possible that the editor automatically detects if the inserted text is a HTML, XHTML or XML start tag and inserts at every second marked position the end tag. Such a feature does not exist in UltraEdit. But with the usage of following small script nearly the same can be achieved.

Before using the script, the positions where to insert the string/tag must be marked in the file. To do this a character must be inserted which is normally not used in the files where this script is used. For example in most HTML, XHTML and XML files the paragraph character § is not present. The script as is expects that the positions where to insert the string/tag are marked with §.

Now when running the script it first asks the user which string to insert and then inserts it either as simple text or as start/end tag pair. An example best demonstrates all possible variations.

File content before running the script. | marks the cursor position.

Input wrote:Here is a text to make §bold§, and here starts another §bold
text§| which ends on the next line to test correct placement
of the cursor after inserting the text/tags.

With ' entered during script execution the result is:

Output1 wrote:Here is a text to make 'bold', and here starts another 'bold
text'| which ends on the next line to test correct placement
of the cursor after inserting the text/tags.

With <span style='font-weight:bold'> entered during script execution the result is:

Output2 wrote:Here is a text to make <span style='font-weight:bold'>bold</span>, and here starts another <span style='font-weight:bold'>bold
text</span>| which ends on the next line to test correct placement
of the cursor after inserting the text/tags.

But sometimes you may want to insert a single line tag. No problem, just append the marker character to end of the tag. For example with <br>§ entered during script execution the result is:

Output3 wrote:Here is a text to make <br>bold<br>, and here starts another <br>bold
text<br>| which ends on the next line to test correct placement
of the cursor after inserting the text/tags.
Attachments
InsertStringMultipleTimes.zip
This ZIP archive file contains the second version of the script with comments and some hints for usage. First version was downloaded 185 times.
(2.93 KiB) Downloaded 3 times
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Return to Scripts