Hello,
I’m fumbling my way along, writing a schedule-building utility for my online students. I want it to load class information from a .txt file, written in NotePad.
I’ve loaded the data as a string, then I used .split("
") to slot the lines of the file into an array. So far so good.
Now, I want the program to forgive empty lines at the end of the file, so I mashed Enter several times as a test and traced the array - I get this:
Item number 0 is apple
Item number 1 is banana
Item number 2 is cheese
Item number 3 is dog food
Item number 4 is eggs
Item number 5 is
Item number 6 is
Item number 7 is
Item number 8 is
Item number 9 is
Item number 10 is undefined
Desired behavior is to hack off elements 5 through 10, the ones that don’t contain human-readable characters. (I assume 5 through 9 are carriage return+linefeed, and 10 is some end-of-file thing? What does Ctrl-Z look like?)
My cunning plan was going to be (pseudocode)
while (the last element isn’t alphanumeric)
{
.pop() the array
}
To my surprise, I’m having major problems finding an “is alphanumeric” or “is printable” method; the closest I’ve found is isNaN which won’t cut it.
Can someone point me in the right direction?
Cheers,
JF
PS: If the solution requires regular expressions, please type slowly. I know almost nothing about those so far.