c# - Linq query to take the value from Array with matching sub string value -


i have string - filterarg , array of string - arraycoldef shown in below code. trying split string filterarg |~| , trying value filterarg matching arraycoldef value. can 1 let me know how value todo commented in code

static void main(string[] args)         {             hashtable ht = new hashtable();             string filterarg = "zipcode=2130|~|zipplace=knapper";             string[] arraycoldef = { "zipcode", "space", "zipplace" };              foreach (var item in arraycoldef)             {                 var key = item;                 var value = filterarg.split(new string[] { "|~|" }, stringsplitoptions.removeemptyentries);//todo: here value should hold = 2130 first itteration                 ht.add(item, value);             }          } 

i think complicated iterating on arraycoldef, it's easier iterate through splited string , extract values. can below.

static void main(string[] args) {     hashtable ht = new hashtable();     string filterarg = "zipcode=2130|~|zipplace=knapper";     string[] arraycoldef = { "zipcode", "space", "zipplace" };      var properties = filterarg.split(new string[] { "|~|" }, stringsplitoptions.removeemptyentries);     foreach (var property in properties)     {         var namevalue = property.split(arraycoldef, stringsplitoptions.removeemptyentries);         var item = property.split('=').first(); // key         var value = namevalue.first().trimstart('='); // value         ht.add(item, value);     } } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -