Last active
May 23, 2018 04:40
-
-
Save shiro01/51ddc728c960b70642c6274c66fe493f to your computer and use it in GitHub Desktop.
Split string with nodejs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function splitString (targetString,separator1,separator2) { | |
console.log('TargetString: "' + targetString + '"'); | |
console.log('Separator1: "' + separator1 + '"'); | |
console.log('Separator1: "' + separator2 + '"'); | |
var arrayOfStrings = targetString.split(separator1); | |
var tmpMap = new Map(); | |
//for (var i = 0; i < arrayOfStrings.length; i++) { | |
// var splitBycolon = arrayOfStrings[i].split(separator2); | |
// tmpMap.set(splitBycolon[0],splitBycolon[1]); | |
//} | |
//arrayOfStrings.forEach(function(val, i) { | |
// console.log(i); | |
arrayOfStrings.forEach(function(val) { | |
var splitBycolon = val.split(separator2); | |
tmpMap.set(splitBycolon[0],splitBycolon[1]); | |
}); | |
return tmpMap; | |
} | |
var originalString = "user1:pass1,user2:pass2,user3:pass3"; | |
var comma = ","; | |
var colon= ":"; | |
var mapOfStrings = splitString(originalString,comma,colon); | |
//for (var key of mapOfStrings.keys()) { | |
// console.log("user : " + key + ", pass : " + mapOfStrings.get(key)); | |
//} | |
console.log("---------"); | |
mapOfStrings.forEach(function(val, key) { | |
console.log(key, val); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment