User to user discussion and support for UltraEdit, UEStudio, UltraCompare, and other IDM applications.

Help with writing and running scripts
3 posts Page 1 of 1
Hi there,

I want to read values into variables. A sample of the file format is at bottom. The only scripting command that I can find to read from the file is:

Code: Select all
var char = UltraEdit.activeDocument.currentChar;

Is this what I should use?

Many thanks for any reply.

Code: Select all
00:28:24,2015-11-06 23:53:11 +0000,Conclusion,,Green,MT42 Beanstalk,MTX
00:25:47,2015-11-06 23:49:56 +0000,Stacked,,Green,MT42 Beanstalk,MTX
Better is to make a selection and use var sString = UltraEdit.activeDocument.selection to assign selected text to variable sString or work directly with the string variable UltraEdit.activeDocument.selection.

On small files up to 20 MiB it is also possible to use something like:

Code: Select all
if (UltraEdit.document.length > 0)  // Is any file opened?
{
   // Define environment for this script.
   UltraEdit.insertMode();
   UltraEdit.columnModeOff();

   // Select everything in active file.
   UltraEdit.activeDocument.selectAll();
   if (UltraEdit.activeDocument.isSel())  // Is the file not empty?
   {
      // Determine line termination type used in active file.
      var sLineTerm;
      if (UltraEdit.activeDocument.lineTerminator < 0) sLineTerm = "\r\n";
      else if (UltraEdit.activeDocument.lineTerminator == 1) sLineTerm = "\n";
      else sLineTerm = "\r";

      // Load entire file content as array of strings into memory with
      // each string being a line from file without line termination.
      var asLines = UltraEdit.activeDocument.selection.split(sLineTerm);

      // Do something with the lines in the array of strings.

      // Join the lines back to a single string (block) and
      // overwrite entire file content with the modified lines.
      UltraEdit.activeDocument.write(asLines.join(sLineTerm));
   }
}
Best regards from Austria
Thank you Mofi.
3 posts Page 1 of 1
cron