Skip to content
Advertisement

“String.substring(int, int) line: not available” causes error

Somehow my if loop using a substring to check a .txt file is causing problems. Without the if loop, everything works fine. But with it, it seems that an empty line in the text file is causing it to crash. It is working until the first empty line in the file, and then I get this error. What could I do about that?

code:

JavaScript

Advertisement

Answer

You might want to also check empty string:

JavaScript

You then might also want to refactor the code to make it more readable:

JavaScript
Advertisement