String separation and combining The Next CEO of Stack OverflowWhat is the difference between String and string in C#?How to check if a string contains a substring in BashHow do I read / convert an InputStream into a String in Java?Creating multiline strings in JavaScriptHow do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I check if a string contains a specific word?Why is char[] preferred over String for passwords?

Anatomically Correct Strange Women In Ponds Distributing Swords

How do we know the LHC results are robust?

How did people program for Consoles with multiple CPUs?

Why here is plural "We went to the movies last night."

Why do remote companies require working in the US?

Unreliable Magic - Is it worth it?

Science fiction (dystopian) short story set after WWIII

How to safely derail a train during transit?

How do I go from 300 unfinished/half written blog posts, to published posts?

What makes a siege story/plot interesting?

What's the point of interval inversion?

Rotate a column

Visit to the USA with ESTA approved before trip to Iran

Why didn't Khan get resurrected in the Genesis Explosion?

The King's new dress

Text adventure game code

Is it my responsibility to learn a new technology in my own time my employer wants to implement?

Term for the "extreme-extension" version of a straw man fallacy?

Anatomically Correct Mesopelagic Aves

Apart from "berlinern", do any other German dialects have a corresponding verb?

Why doesn't a table tennis ball float on the surface? How do we calculate buoyancy here?

Should I tutor a student who I know has cheated on their homework?

Is it safe to use c_str() on a temporary string?

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?



String separation and combining



The Next CEO of Stack OverflowWhat is the difference between String and string in C#?How to check if a string contains a substring in BashHow do I read / convert an InputStream into a String in Java?Creating multiline strings in JavaScriptHow do I make the first letter of a string uppercase in JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?Does Python have a string 'contains' substring method?How do I check if a string contains a specific word?Why is char[] preferred over String for passwords?










-2















I have a challenge that I am trying to solve and cannot seem to come up with a solid solution.



I have 3 records like this:



"a,b,c,d,e","1,2,3,4,5","record 1"
"f,g,h,i","11,12,15,16","record 2"
"x,y,z","19,20,21","record 3"


Looking to create this output



"a,1"
"b,2"
"c,3"
"d,4"
"e,5"
...
...
"y,20"
"z,21"


How would I go about this using java-script or



I have have worked out how to separate each string but collecting both substrings and looping through seems to be a challenge.










share|improve this question
























  • are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

    – Guy Louzon
    Sep 27 '18 at 9:50












  • @GuyL - That's definitely not JSON.

    – T.J. Crowder
    Sep 27 '18 at 9:51






  • 2





    Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

    – Darren Sweeney
    Sep 27 '18 at 9:52











  • @T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

    – Guy Louzon
    Sep 27 '18 at 9:52






  • 1





    it's not clear what your input is. Is one line a string, or 3 strings in an array?

    – Jeff
    Sep 27 '18 at 9:54















-2















I have a challenge that I am trying to solve and cannot seem to come up with a solid solution.



I have 3 records like this:



"a,b,c,d,e","1,2,3,4,5","record 1"
"f,g,h,i","11,12,15,16","record 2"
"x,y,z","19,20,21","record 3"


Looking to create this output



"a,1"
"b,2"
"c,3"
"d,4"
"e,5"
...
...
"y,20"
"z,21"


How would I go about this using java-script or



I have have worked out how to separate each string but collecting both substrings and looping through seems to be a challenge.










share|improve this question
























  • are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

    – Guy Louzon
    Sep 27 '18 at 9:50












  • @GuyL - That's definitely not JSON.

    – T.J. Crowder
    Sep 27 '18 at 9:51






  • 2





    Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

    – Darren Sweeney
    Sep 27 '18 at 9:52











  • @T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

    – Guy Louzon
    Sep 27 '18 at 9:52






  • 1





    it's not clear what your input is. Is one line a string, or 3 strings in an array?

    – Jeff
    Sep 27 '18 at 9:54













-2












-2








-2








I have a challenge that I am trying to solve and cannot seem to come up with a solid solution.



I have 3 records like this:



"a,b,c,d,e","1,2,3,4,5","record 1"
"f,g,h,i","11,12,15,16","record 2"
"x,y,z","19,20,21","record 3"


Looking to create this output



"a,1"
"b,2"
"c,3"
"d,4"
"e,5"
...
...
"y,20"
"z,21"


How would I go about this using java-script or



I have have worked out how to separate each string but collecting both substrings and looping through seems to be a challenge.










share|improve this question
















I have a challenge that I am trying to solve and cannot seem to come up with a solid solution.



I have 3 records like this:



"a,b,c,d,e","1,2,3,4,5","record 1"
"f,g,h,i","11,12,15,16","record 2"
"x,y,z","19,20,21","record 3"


Looking to create this output



"a,1"
"b,2"
"c,3"
"d,4"
"e,5"
...
...
"y,20"
"z,21"


How would I go about this using java-script or



I have have worked out how to separate each string but collecting both substrings and looping through seems to be a challenge.







javascript string substring






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 14:06









Cœur

19.1k9114155




19.1k9114155










asked Sep 27 '18 at 9:49









Grahame PearsonGrahame Pearson

1




1












  • are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

    – Guy Louzon
    Sep 27 '18 at 9:50












  • @GuyL - That's definitely not JSON.

    – T.J. Crowder
    Sep 27 '18 at 9:51






  • 2





    Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

    – Darren Sweeney
    Sep 27 '18 at 9:52











  • @T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

    – Guy Louzon
    Sep 27 '18 at 9:52






  • 1





    it's not clear what your input is. Is one line a string, or 3 strings in an array?

    – Jeff
    Sep 27 '18 at 9:54

















  • are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

    – Guy Louzon
    Sep 27 '18 at 9:50












  • @GuyL - That's definitely not JSON.

    – T.J. Crowder
    Sep 27 '18 at 9:51






  • 2





    Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

    – Darren Sweeney
    Sep 27 '18 at 9:52











  • @T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

    – Guy Louzon
    Sep 27 '18 at 9:52






  • 1





    it's not clear what your input is. Is one line a string, or 3 strings in an array?

    – Jeff
    Sep 27 '18 at 9:54
















are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

– Guy Louzon
Sep 27 '18 at 9:50






are these records in JSON format ? they do not seem to be strings... what's the exact structure for each record?

– Guy Louzon
Sep 27 '18 at 9:50














@GuyL - That's definitely not JSON.

– T.J. Crowder
Sep 27 '18 at 9:51





@GuyL - That's definitely not JSON.

– T.J. Crowder
Sep 27 '18 at 9:51




2




2





Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

– Darren Sweeney
Sep 27 '18 at 9:52





Welcome to SO. What have you tried? It is expected that you at least try to find a solution yourself and if you have issues, then ask questions about the specific issues.

– Darren Sweeney
Sep 27 '18 at 9:52













@T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

– Guy Louzon
Sep 27 '18 at 9:52





@T.J.Crowder its doesn't seem so in the question,but what datatype should it be in, this is a JS question...

– Guy Louzon
Sep 27 '18 at 9:52




1




1





it's not clear what your input is. Is one line a string, or 3 strings in an array?

– Jeff
Sep 27 '18 at 9:54





it's not clear what your input is. Is one line a string, or 3 strings in an array?

– Jeff
Sep 27 '18 at 9:54












1 Answer
1






active

oldest

votes


















1














This can get a little bit Tricky if you dont have a constant format.



In this example i have two strings and each sub-string is separated by ",".



Also both strings should be the same length.



I return the result as an array here. You can append it to a existing string instead.






s1 = "1,2,3,4,5";
s2 = "a,b,c,d,e";
s3 = [];
for(i=0; s1.length>i;i++)
if(s1[i] != ",")
s3.push(s1[i]+","+s2[i]);


console.log(s3);





Since im not sure if i did understand the Question correctly...
If you dont understand something or the answer is not what you excepted, let me know in the comments and i will try to adapt to it.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52534152%2fstring-separation-and-combining%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This can get a little bit Tricky if you dont have a constant format.



    In this example i have two strings and each sub-string is separated by ",".



    Also both strings should be the same length.



    I return the result as an array here. You can append it to a existing string instead.






    s1 = "1,2,3,4,5";
    s2 = "a,b,c,d,e";
    s3 = [];
    for(i=0; s1.length>i;i++)
    if(s1[i] != ",")
    s3.push(s1[i]+","+s2[i]);


    console.log(s3);





    Since im not sure if i did understand the Question correctly...
    If you dont understand something or the answer is not what you excepted, let me know in the comments and i will try to adapt to it.






    share|improve this answer



























      1














      This can get a little bit Tricky if you dont have a constant format.



      In this example i have two strings and each sub-string is separated by ",".



      Also both strings should be the same length.



      I return the result as an array here. You can append it to a existing string instead.






      s1 = "1,2,3,4,5";
      s2 = "a,b,c,d,e";
      s3 = [];
      for(i=0; s1.length>i;i++)
      if(s1[i] != ",")
      s3.push(s1[i]+","+s2[i]);


      console.log(s3);





      Since im not sure if i did understand the Question correctly...
      If you dont understand something or the answer is not what you excepted, let me know in the comments and i will try to adapt to it.






      share|improve this answer

























        1












        1








        1







        This can get a little bit Tricky if you dont have a constant format.



        In this example i have two strings and each sub-string is separated by ",".



        Also both strings should be the same length.



        I return the result as an array here. You can append it to a existing string instead.






        s1 = "1,2,3,4,5";
        s2 = "a,b,c,d,e";
        s3 = [];
        for(i=0; s1.length>i;i++)
        if(s1[i] != ",")
        s3.push(s1[i]+","+s2[i]);


        console.log(s3);





        Since im not sure if i did understand the Question correctly...
        If you dont understand something or the answer is not what you excepted, let me know in the comments and i will try to adapt to it.






        share|improve this answer













        This can get a little bit Tricky if you dont have a constant format.



        In this example i have two strings and each sub-string is separated by ",".



        Also both strings should be the same length.



        I return the result as an array here. You can append it to a existing string instead.






        s1 = "1,2,3,4,5";
        s2 = "a,b,c,d,e";
        s3 = [];
        for(i=0; s1.length>i;i++)
        if(s1[i] != ",")
        s3.push(s1[i]+","+s2[i]);


        console.log(s3);





        Since im not sure if i did understand the Question correctly...
        If you dont understand something or the answer is not what you excepted, let me know in the comments and i will try to adapt to it.






        s1 = "1,2,3,4,5";
        s2 = "a,b,c,d,e";
        s3 = [];
        for(i=0; s1.length>i;i++)
        if(s1[i] != ",")
        s3.push(s1[i]+","+s2[i]);


        console.log(s3);





        s1 = "1,2,3,4,5";
        s2 = "a,b,c,d,e";
        s3 = [];
        for(i=0; s1.length>i;i++)
        if(s1[i] != ",")
        s3.push(s1[i]+","+s2[i]);


        console.log(s3);






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 27 '18 at 10:10









        TibixTibix

        355312




        355312





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52534152%2fstring-separation-and-combining%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved