PDA

View Full Version : Count Lines - Javascript



webdeveloper
03 Aug 2010, 10:57 PM
Hi,

I would like to write a simple JavaScript code that can load up an external JS file and then calculate the number of lines in the code.

Is there a built-in file i/o function in JavaScript that I can use to open a .JS file and start reading each line and calculate the number of lines?

<CrGeary.com/>
04 Aug 2010, 01:39 AM
If you load the content of the JS file into a string, then follow this: http://www.knowledgesutra.com/forums/topic/20323-a-function-to-count-the-number-of-lines-in-a-string/

That should do the trick.

--
I have a feeling this would be much easier to do this with server side programming, and it would probably work better too.