daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest May 27th, 2018 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function splitString (targetString,separator1,separator2) {
  2.  
  3.     console.log('TargetString: "' + targetString + '"');
  4.     console.log('Separator1: "' + separator1 + '"');
  5.     console.log('Separator1: "' + separator2 + '"');
  6.    
  7.     var arrayOfStrings = targetString.split(separator1);
  8.     var tmpMap = new Map();
  9.     //for (var i = 0; i < arrayOfStrings.length; i++) {
  10.     //    var splitBycolon = arrayOfStrings[i].split(separator2);
  11.     //    tmpMap.set(splitBycolon[0],splitBycolon[1]);
  12.     //}
  13.     //arrayOfStrings.forEach(function(val, i) {
  14.     //    console.log(i);
  15.     arrayOfStrings.forEach(function(val) {
  16.         var splitBycolon = val.split(separator2);
  17.         tmpMap.set(splitBycolon[0],splitBycolon[1]);
  18.     });
  19.     return tmpMap;
  20. }
  21.  
  22. var originalString = "user1:pass1,user2:pass2,user3:pass3";
  23. var comma = ",";
  24. var colon= ":";
  25. var mapOfStrings = splitString(originalString,comma,colon);
  26. //for (var key of mapOfStrings.keys()) {
  27. //  console.log("user : " + key + ", pass : " +  mapOfStrings.get(key));
  28. //}
  29.  
  30. console.log("---------");
  31. mapOfStrings.forEach(function(val, key) {
  32.   console.log(key, val);
  33. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top