View Full Version : Substring and array

06-13-2003, 04:26 PM
Is there any overwhelming reason to read a string into an array as opposed to just using substring to grab values from it?

I have filenames with a specific scheme that has date, topic, etc. embedded in it (i.e. 06122003_request_blahblah.doc) It is a very fixed format, so substring(0,8) will always be the date field and so on.

Since I am going to parse this, should I just use substring to grab everything I need or use substring to read it into an array and then play around with the array?

I guess performance is what I'm concerned about. Not so much ease of programming (that's trivial).

06-13-2003, 05:02 PM
Hmmm - depends on what you're doing to do with this when once you've parsed it.

If all the key parts of the filename are separated by an underscore, then you can do this

var filename = "06122003_request_blahblah.doc";
var file = filename.split( /[_.]/g );

file is now an array that looks like this


06-13-2003, 06:11 PM
That's a much easier/compact way than the way I did it. I used functions like getDate(filename) and substring to grab everything. I'm going to modify my code using your idea and switch over to a two dimensional array to hold everything.