Yes, that reformatting is easy to achieve with a replace all.
As non regular expression replace all:
Find what:
'
Replace with:
'^p
That's simple, but has a disadvantage. This replace inserts one more DOS/Windows line termination even If there is already a line termination after
'.
As UltraEdit regular expression replace all:
Find what:
'^([~^r^n]^)
Replace with:
'^p^1
That's better than above because it does not insert carriage return (CR) and line-feed (LF) after
' if there is already a newline character after
'.
But it has also 2 disadvantages: If there is
'' in file, it inserts CR+LF only between the two
'', but none after
'. And it does not append CR+LF to end of file if the file ends with
'.
As Perl regular expression replace all:
Find what:
'(?![\r\n])
Replace with:
'\r\n
This expression has no disadvantages. It works always for inserting CR+LF after each
' where next character is whether a carriage return nor a line-feed which results in even appending CR+LF at end of file if there is none and file ends with
' as last character.
The Perl regular expression replace all can be recorded into a macro which has a hotkey assigned for quick execution by key and which is stored into a macro file (with other macros) being configured for automatic load on startup of UltraEdit for being available immediately after starting UltraEdit.
The UltraEdit macro code:
Code: Select all
InsertMode
ColumnModeOff
HexOff
Top
PerlReOn
Find MatchCase RegExp "'(?![\r\n])"
Replace All "'\r\n"
But is also possible to write an UltraEdit script with the code below which is added to the
Script List with a hotkey assigned to the script for quick execution at any time.
Code: Select all
if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
var nLine = UltraEdit.activeDocument.currentLineNum;
var nColumn = UltraEdit.activeDocument.currentColumnNum;
// Move caret to top of the active file.
UltraEdit.activeDocument.top();
// Define the options for Perl regular expression replace all.
UltraEdit.perlReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.searchInColumn=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
if(!UltraEdit.activeDocument.findReplace.replace("'(?![\\r\\n])","'\\r\\n"))
{
UltraEdit.activeDocument.gotoLine(nLine,nColumn);
}
}
The script restores position of caret in active file if the Perl regular expression replace all has not inserted anywhere CR+LF.