Javascript remove empty slots from array

broken image
broken image

As we read each line we check to see if the line is blank. Because we can’t directly edit a text file we have to do this instead: First, we read in the text file line-by-line. As you probably know, manipulating text files often involves coming up with work-arounds. Let’s talk about the basic idea before we get into the nitty-gritty details of how the script works. Set objFile = objFSO.OpenTextFile(“C:\Scripts\Test.txt”, ForWriting) StrNewContents = strNewContents & strLine & vbCrLf Set objFile = objFSO.OpenTextFile(“C:\Scripts\Test.txt”, ForReading) Set objFSO = CreateObject(“Scripting.FileSystemObject”) What you’d like is for the text file to look like this: Line 1Ĭan you do that using a script? Of course you can: Const ForReading = 1 We’re assuming that you have a text file that looks something like this: Line 1 Not bad for a dead technology that nobody uses, huh? What’s the moral to all this? It’s now 2006, and the first question being tackled in the Hey, Scripting Guy! column is one dealing with text files.

broken image