lundi 1 décembre 2014

How Do I Parse a Pipe-Delimited String into Key-Value Pairs in Javascript


I want to parse the following sort of string into key-value pairs in a Javascript object:



var stringVar = 'PLNC||0|EOR|<br>SUBD|Pines|1|EOR|<br>CITY|Fort Myers|1|EOR|<br>';


Each word of 4 capital letters (PLNC, SUBD, and CITY) is to be a key, while the word(s) in the immediately following pipe are to be the value (the first one, for PLNC, would be undefined, the one for SUBD would be 'Pines', the one for CITY would be 'Fort Myers').


Note that '|EOR|

' immediately precedes every key-value pair.


What is the best way of doing this?





Aucun commentaire:

Enregistrer un commentaire