Welcome to the IDM Forum. This forum is meant as a user-to-user support mechanism where users can share knowledge and tips for all IDM software.
Since these forums are user-to-user based, IDM does not regularly read or reply to the posts in this forum. For problem reports, suggestions, or feature requests, you must email us directly. Our trained technical support staff answers most inquiries within 30 minutes.
UltraEdit.ueReOn();
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=false;
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean") {
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=false;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.top();
UltraEdit.perlReOn(); // Using Perl regular expression engine.
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=false;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true; // Regular expression ON
UltraEdit.activeDocument.findReplace.searchDown=true;
if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean") {
UltraEdit.activeDocument.findReplace.searchInColumn=false;
}
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replaceAll=true; // Replace All ON
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
// Replace word "blah" anywhere within first value of a row by "xyzk".
UltraEdit.activeDocument.findReplace.replace("^([^;\\r\\n]*)blah", "\\1xyzk");
// Replace word "blah" anywhere within second value of a row by
// "xyzk", but only if first value in row contains the word "xyzk".
UltraEdit.activeDocument.findReplace.replace("^([^;\\r\\n]*xyzk.*;[^;\\r\\n]*)blah", "\\1xyzk");
// Replace word "blah" anywhere within second value of a row by "three".
UltraEdit.activeDocument.findReplace.replace("^(.*?;[^;\\r\\n]*)blah", "\\1three");
// Replace word "add" anywhere within third value of a row by "zpp".
UltraEdit.activeDocument.findReplace.replace("^(.*?;.*?;[^;\\r\\n]*)add", "\\1zpp");
// Replace word "odd" anywhere within third value of a row by "ipp".
UltraEdit.activeDocument.findReplace.replace("^(.*?;.*?;[^;\\r\\n]*)odd", "\\1ipp");

if (UltraEdit.document.length > 0) // Is any file opened?
{
// Define environment for this script.
UltraEdit.insertMode();
UltraEdit.columnModeOff();
UltraEdit.activeDocument.selectAll(); // Select the entire file.
// Is anything selected, i.e. file is not empty?
if (UltraEdit.activeDocument.isSel())
{
// Define the exception words in array with a counter.
var asExceptionWords = {};
asExceptionWords["one"] = 0;
asExceptionWords["two"] = 0;
asExceptionWords["three"] = 0;
// Get all DOS terminated lines into an array of strings.
var asLines = UltraEdit.activeDocument.selection.split("\r\n");
// Processing all lines in the array.
var nModifiedLines = nModifiedFields = 0;
for (var nLine = 0; nLine < asLines.length; nLine++)
{
if (!asLines[nLine].length) continue; // Skip all empty lines.
// Split the line into fields at every semicolon.
var asFields = asLines[nLine].split(";");
var bFieldModified = false;
for (var nField = 0; nField < asFields.length; nField++)
{
// Skip all empty fields, i.e. two semicolons in sequence.
if (!asFields[nField].length) continue;
// Does this field not contain an exception word?
if (asExceptionWords[asFields[nField]] == null)
{
var sField = asFields[nField];
// Make the character by character replaces.
sField = sField.replace(/a/g,"x");
sField = sField.replace(/b/g,"y");
sField = sField.replace(/c/g,"r");
sField = sField.replace(/z/g,"i");
// Is the string of this field modified?
if (sField != asFields[nField])
{
asFields[nField] = sField;
bFieldModified = true;
nModifiedFields++;
}
}
else // Not nearly necessary but perhaps interesting
{ // is which exception word was found how often.
asExceptionWords[asFields[nField]]++;
}
}
if (bFieldModified) // Was any field in this line modified?
{
asLines[nLine] = asFields.join(";");
nModifiedLines++;
}
}
if (nModifiedLines) // Was any line modified?
{
// Rebuild the block in user clipboard 9 and paste the
// lines over the still selected lines in the active file.
// Pasting a large block is much faster than writing.
UltraEdit.selectClipboard(9);
UltraEdit.clipboardContent = asLines.join("\r\n");
UltraEdit.activeDocument.paste();
UltraEdit.clearClipboard();
UltraEdit.selectClipboard(0);
}
// Move caret to top of file which cancels also the
// selection in the case there was nothing modified.
UltraEdit.activeDocument.top();
// Output a summary in the output window.
UltraEdit.outputWindow.showStatus = false;
if (UltraEdit.outputWindow.visible == false)
{
UltraEdit.outputWindow.showWindow(true);
}
UltraEdit.outputWindow.clear();
for (var sWord in asExceptionWords)
{
var nCount = asExceptionWords[sWord];
UltraEdit.outputWindow.write("Exception word \""+sWord+"\" found "+nCount+" time"+((nCount==1) ? "." : "s."));
}
UltraEdit.outputWindow.write("\nSummary: "+nModifiedFields+" field"+((nModifiedFields==1) ? "" : "s")+
" modified in "+nModifiedLines+" line"+((nModifiedLines==1) ? "." : "s."));
}
}