How to optimally write contents of array to a file

How to optimally write contents of array to a file

2
NewbieNewbie
2

    Sep 07, 2010#1

    I have an array of strings and want to flush out to a new file. Is there a way to optimally write the contents of the array to a file?

    I know the following will do what I want, but I want to do it faster:

    for (var i = 0, len = myResults.length; i < len; i++)
    {
    UltraEdit.activeDocument.write(myResults);
    }

    6,686585
    Grand MasterGrand Master
    6,686585

      Sep 07, 2010#2

      Well, that depends on what type of array myResults is. Is it an array of integer values, of characters or of strings? Do you want every element of the array on a new line or not?

      Let us assume myResults is an array of strings and you want every string on a new line and the strings do not contain line terminations. In this case it would be best to concatenate all the strings first to a single string and then output this very long single string.

      var sOutput = myResults.join("\r\n");
      if (sOutput.length) UltraEdit.activeDocument.write(sOutput);

      Scripts executed with UltraEdit are fast when they avoid display updates as much as possible by doing as much as possible in memory and as less as possible in the active document window or any other document window partly visible.

      The JavaScript core method join("") of the array object can be used also for arrays with integer values or characters.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Sep 08, 2010#3

        Thank you! That reduced my elapse time by 25%.