Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

how to use split() method for 2 separators

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am using axaj to get the values for the dropdown. i have values in the form of pair as docid and its name. the name i want to display in the drop down and its value should be docID. so for this i have below code:

//Insert the values
var resultStringArr = new Array();
//reslutSringArrdocid= resultString.split('=');
resultStringArr = resultString.split(",");
for(var n = 0; n < resultStringArr.length-1; n++) {

grpElement.add(new Option(resultStringArr[n],resultStringArr[n]));

grpElement.disabled = false;

result string will be in this form: docid=abc,docid2=bcd,
so here docid i want to put as value and display name in the dropdown as abc

from the code so resultStringArr = resultString.split(",");
i am able to split the line and now i am getting in the drop down as docid=abc next value as docid2=bcd
so i want to further split this into docid and abc so that docid will be the value and display name will be abc.

Can any one provide me code for this .

Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey you will find lot more examples in[yahoo,google] search.


Posts: 15385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
reason why you are not doing a second split in your loop?

1) split on comma results in ["foo=1","bar=2"]
2) for loop through comma array
3) split the comma array index on equals sign results on ["foo", "1"]
4) add you option via the new equals sign array

It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic