Good parser for key = value CRLF file
3 answers
Assuming that CR
, LF
and =
are all protected characters (i.e. they cannot appear in key
or value
), you can simply do:
var str = "key=value\r\nkey2=value2\r\n";
var lines = str.split("\r\n");
var map = {};
for(var i = 0; i < lines.length; i++) {
var pieces = lines[i].split("=");
if (pieces.length == 2)
map[pieces[0]] = pieces[1];
}
+6
source to share
http://krook.org/jsdom/ see String.split method. first split into crlf (I suppose) and then split into "="
0
source to share