Any sample code how to make hashmap or similar list from
key=value CRLF
key2=value2 CRLF
Any sample code how to make hashmap or similar list from
key=value CRLF
key2=value2 CRLF
http://krook.org/jsdom/ see the String.split method. split first on crlf (\r\n I believe) and then split on "="
Assuming that CR
, LF
, and =
are all protected characters (i.e., they cannot occur in key
or value
), you could 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];
}
This should do it:
var str = "key=value\r\nkey2=value2\r\n";
var re = /([^=]*)=(.*?)\r\n/g, match, map = { };
while (match = re.exec(str)) {
map[match[1]] = match[2];
}