f=storage.read("...");
var line,linestart = 0;
lineend = f.indexOf("\n");
while (lineend>=0) {
line = f.substring(linestart,lineend);
.... = line.split(',');
linestart = lineend+1;
lineend = f.indexOf("\n",linestart);
}
Just a bit of background: Storage.read returns a string that's basically just a pointer to external flash memory - so it can be huge. You can use it like any other string, but if you split it you're then creating potentially thousands of new strings in RAM which will use up all the available memory.
I guess there's no JavaScript function that is the equivalent of .split(..).forEach(..) but I guess it's something we could add.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
As @fanoush says you can use indexOf - there's actually an example of this in the planetarium app: https://github.com/espruino/BangleApps/blob/master/apps/planetarium/planetarium.app.js#L107
Just a bit of background:
Storage.read
returns a string that's basically just a pointer to external flash memory - so it can be huge. You can use it like any other string, but if yousplit
it you're then creating potentially thousands of new strings in RAM which will use up all the available memory.I guess there's no JavaScript function that is the equivalent of
.split(..).forEach(..)
but I guess it's something we could add.