Parse CSV to Kotlin List












1















I'm a bit confused.
I have this csv line with double quote("") as grouped strings, and want to convert to Kotlin List.
However it produces a single array with size 1.
I want to be able to get the group, assumes at position 2.



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)")
Log.d("size:", list.size.toString() + " - subjects:" + list[2])


This gives me error



java.lang.IndexOutOfBoundsException: Index: 2, Size: 1









share|improve this question























  • What is your expected result?

    – forpas
    Jan 1 at 18:08











  • "Subject 1, Subject 2, Subject 3"

    – luca ditrimma
    Jan 1 at 18:09











  • Isn't the delimeter " in this case?

    – forpas
    Jan 1 at 18:17
















1















I'm a bit confused.
I have this csv line with double quote("") as grouped strings, and want to convert to Kotlin List.
However it produces a single array with size 1.
I want to be able to get the group, assumes at position 2.



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)")
Log.d("size:", list.size.toString() + " - subjects:" + list[2])


This gives me error



java.lang.IndexOutOfBoundsException: Index: 2, Size: 1









share|improve this question























  • What is your expected result?

    – forpas
    Jan 1 at 18:08











  • "Subject 1, Subject 2, Subject 3"

    – luca ditrimma
    Jan 1 at 18:09











  • Isn't the delimeter " in this case?

    – forpas
    Jan 1 at 18:17














1












1








1








I'm a bit confused.
I have this csv line with double quote("") as grouped strings, and want to convert to Kotlin List.
However it produces a single array with size 1.
I want to be able to get the group, assumes at position 2.



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)")
Log.d("size:", list.size.toString() + " - subjects:" + list[2])


This gives me error



java.lang.IndexOutOfBoundsException: Index: 2, Size: 1









share|improve this question














I'm a bit confused.
I have this csv line with double quote("") as grouped strings, and want to convert to Kotlin List.
However it produces a single array with size 1.
I want to be able to get the group, assumes at position 2.



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)")
Log.d("size:", list.size.toString() + " - subjects:" + list[2])


This gives me error



java.lang.IndexOutOfBoundsException: Index: 2, Size: 1






kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 18:04









luca ditrimmaluca ditrimma

7119




7119













  • What is your expected result?

    – forpas
    Jan 1 at 18:08











  • "Subject 1, Subject 2, Subject 3"

    – luca ditrimma
    Jan 1 at 18:09











  • Isn't the delimeter " in this case?

    – forpas
    Jan 1 at 18:17



















  • What is your expected result?

    – forpas
    Jan 1 at 18:08











  • "Subject 1, Subject 2, Subject 3"

    – luca ditrimma
    Jan 1 at 18:09











  • Isn't the delimeter " in this case?

    – forpas
    Jan 1 at 18:17

















What is your expected result?

– forpas
Jan 1 at 18:08





What is your expected result?

– forpas
Jan 1 at 18:08













"Subject 1, Subject 2, Subject 3"

– luca ditrimma
Jan 1 at 18:09





"Subject 1, Subject 2, Subject 3"

– luca ditrimma
Jan 1 at 18:09













Isn't the delimeter " in this case?

– forpas
Jan 1 at 18:17





Isn't the delimeter " in this case?

– forpas
Jan 1 at 18:17












4 Answers
4






active

oldest

votes


















1














The given regex just works fine. Currently you try to split the string s at the raw regex as delimeter, which does not exists in s. Simply add .toRegex() to the regex.



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)".toRegex())
Log.d("size:", list.size.toString() + " - subjects:" + list[2])





share|improve this answer
























  • this work like charm!

    – luca ditrimma
    Jan 2 at 0:57



















1














Split by " and you get a list with size = 3

and what you need is at index = 1.

Then you need to split the item index = 0 by , for the name and the number:



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
val list: List<String> = s.split(""")
val listStart = list[0].split(",")
val subjects = list[1].trim()
val name = listStart[0].trim()
val number = listStart[1].trim()


Another way if you don't really need the list but only the values:



val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
val subjects = s.substringAfter(""").substringBefore(""").trim()
val name = s.substringBefore(",").trim()
val number = s.substringAfter(",").substringBefore(",").trim()

println("name: " + name)
println("number: " + number)
println("subjects: " + subjects)


will print:



name: John Doe
number: 13
subjects:Subject 1, Subject 2, Subject 3





share|improve this answer


























  • This only works if the fields don't contain the separator though

    – EpicPandaForce
    Jan 1 at 18:23











  • Which separator?

    – forpas
    Jan 1 at 18:24











  • thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

    – luca ditrimma
    Jan 1 at 18:33













  • See my edited answer

    – forpas
    Jan 1 at 18:40











  • Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

    – luca ditrimma
    Jan 1 at 18:51



















1














I'd recommend not doing the parsing yourself, but using an existing library.  (For example, I found Apache Commons CSV easy to use from Kotlin.)



Although writing parsing code can be fun, and CSV seems simple enough, it has enough complications and variations that unless you created it yourself, you're likely to miss some cases.  (Not just escaped quotes, but other escaped characters, nested quotes, fields which include newlines, comment lines…  And my favourite gotcha: MS Excel uses the machine's list separator, which can be semicolon or another character instead of comma to separate fields!)



Trust me, I've been there…






share|improve this answer
























  • this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

    – luca ditrimma
    Jan 1 at 23:59



















1














Is this helpful? Not much of a test since I make no actual assertions, but maybe enough to put you onto the idea.



@Test
fun should_tolerate_quoted_commas_in_third_column() {
val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
val pattern = Pattern.compile(",")
s.split(regex=pattern, limit=3).forEach( System.out::println )
}


output:



John Doe
13
"Subject 1, Subject 2, Subject 3"


EDIT 1:



Similarly...



@Test
fun should_make_list_from_quoted_string_in_third_column() {
val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
val outerList = s.split(regex = Pattern.compile(","), limit = 3)
outerList[2].replace(""","").split(",").forEach( System.out::println )
}





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%2f53997728%2fparse-csv-to-kotlin-list%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    The given regex just works fine. Currently you try to split the string s at the raw regex as delimeter, which does not exists in s. Simply add .toRegex() to the regex.



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)".toRegex())
    Log.d("size:", list.size.toString() + " - subjects:" + list[2])





    share|improve this answer
























    • this work like charm!

      – luca ditrimma
      Jan 2 at 0:57
















    1














    The given regex just works fine. Currently you try to split the string s at the raw regex as delimeter, which does not exists in s. Simply add .toRegex() to the regex.



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)".toRegex())
    Log.d("size:", list.size.toString() + " - subjects:" + list[2])





    share|improve this answer
























    • this work like charm!

      – luca ditrimma
      Jan 2 at 0:57














    1












    1








    1







    The given regex just works fine. Currently you try to split the string s at the raw regex as delimeter, which does not exists in s. Simply add .toRegex() to the regex.



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)".toRegex())
    Log.d("size:", list.size.toString() + " - subjects:" + list[2])





    share|improve this answer













    The given regex just works fine. Currently you try to split the string s at the raw regex as delimeter, which does not exists in s. Simply add .toRegex() to the regex.



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    var list: List<String> = s.split(",(?=([^"]*"[^"]*")*[^"]*$)".toRegex())
    Log.d("size:", list.size.toString() + " - subjects:" + list[2])






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 1 at 20:56









    pixix4pixix4

    3311311




    3311311













    • this work like charm!

      – luca ditrimma
      Jan 2 at 0:57



















    • this work like charm!

      – luca ditrimma
      Jan 2 at 0:57

















    this work like charm!

    – luca ditrimma
    Jan 2 at 0:57





    this work like charm!

    – luca ditrimma
    Jan 2 at 0:57













    1














    Split by " and you get a list with size = 3

    and what you need is at index = 1.

    Then you need to split the item index = 0 by , for the name and the number:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val list: List<String> = s.split(""")
    val listStart = list[0].split(",")
    val subjects = list[1].trim()
    val name = listStart[0].trim()
    val number = listStart[1].trim()


    Another way if you don't really need the list but only the values:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val subjects = s.substringAfter(""").substringBefore(""").trim()
    val name = s.substringBefore(",").trim()
    val number = s.substringAfter(",").substringBefore(",").trim()

    println("name: " + name)
    println("number: " + number)
    println("subjects: " + subjects)


    will print:



    name: John Doe
    number: 13
    subjects:Subject 1, Subject 2, Subject 3





    share|improve this answer


























    • This only works if the fields don't contain the separator though

      – EpicPandaForce
      Jan 1 at 18:23











    • Which separator?

      – forpas
      Jan 1 at 18:24











    • thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

      – luca ditrimma
      Jan 1 at 18:33













    • See my edited answer

      – forpas
      Jan 1 at 18:40











    • Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

      – luca ditrimma
      Jan 1 at 18:51
















    1














    Split by " and you get a list with size = 3

    and what you need is at index = 1.

    Then you need to split the item index = 0 by , for the name and the number:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val list: List<String> = s.split(""")
    val listStart = list[0].split(",")
    val subjects = list[1].trim()
    val name = listStart[0].trim()
    val number = listStart[1].trim()


    Another way if you don't really need the list but only the values:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val subjects = s.substringAfter(""").substringBefore(""").trim()
    val name = s.substringBefore(",").trim()
    val number = s.substringAfter(",").substringBefore(",").trim()

    println("name: " + name)
    println("number: " + number)
    println("subjects: " + subjects)


    will print:



    name: John Doe
    number: 13
    subjects:Subject 1, Subject 2, Subject 3





    share|improve this answer


























    • This only works if the fields don't contain the separator though

      – EpicPandaForce
      Jan 1 at 18:23











    • Which separator?

      – forpas
      Jan 1 at 18:24











    • thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

      – luca ditrimma
      Jan 1 at 18:33













    • See my edited answer

      – forpas
      Jan 1 at 18:40











    • Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

      – luca ditrimma
      Jan 1 at 18:51














    1












    1








    1







    Split by " and you get a list with size = 3

    and what you need is at index = 1.

    Then you need to split the item index = 0 by , for the name and the number:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val list: List<String> = s.split(""")
    val listStart = list[0].split(",")
    val subjects = list[1].trim()
    val name = listStart[0].trim()
    val number = listStart[1].trim()


    Another way if you don't really need the list but only the values:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val subjects = s.substringAfter(""").substringBefore(""").trim()
    val name = s.substringBefore(",").trim()
    val number = s.substringAfter(",").substringBefore(",").trim()

    println("name: " + name)
    println("number: " + number)
    println("subjects: " + subjects)


    will print:



    name: John Doe
    number: 13
    subjects:Subject 1, Subject 2, Subject 3





    share|improve this answer















    Split by " and you get a list with size = 3

    and what you need is at index = 1.

    Then you need to split the item index = 0 by , for the name and the number:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val list: List<String> = s.split(""")
    val listStart = list[0].split(",")
    val subjects = list[1].trim()
    val name = listStart[0].trim()
    val number = listStart[1].trim()


    Another way if you don't really need the list but only the values:



    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val subjects = s.substringAfter(""").substringBefore(""").trim()
    val name = s.substringBefore(",").trim()
    val number = s.substringAfter(",").substringBefore(",").trim()

    println("name: " + name)
    println("number: " + number)
    println("subjects: " + subjects)


    will print:



    name: John Doe
    number: 13
    subjects:Subject 1, Subject 2, Subject 3






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 1 at 19:57

























    answered Jan 1 at 18:20









    forpasforpas

    16.4k3627




    16.4k3627













    • This only works if the fields don't contain the separator though

      – EpicPandaForce
      Jan 1 at 18:23











    • Which separator?

      – forpas
      Jan 1 at 18:24











    • thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

      – luca ditrimma
      Jan 1 at 18:33













    • See my edited answer

      – forpas
      Jan 1 at 18:40











    • Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

      – luca ditrimma
      Jan 1 at 18:51



















    • This only works if the fields don't contain the separator though

      – EpicPandaForce
      Jan 1 at 18:23











    • Which separator?

      – forpas
      Jan 1 at 18:24











    • thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

      – luca ditrimma
      Jan 1 at 18:33













    • See my edited answer

      – forpas
      Jan 1 at 18:40











    • Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

      – luca ditrimma
      Jan 1 at 18:51

















    This only works if the fields don't contain the separator though

    – EpicPandaForce
    Jan 1 at 18:23





    This only works if the fields don't contain the separator though

    – EpicPandaForce
    Jan 1 at 18:23













    Which separator?

    – forpas
    Jan 1 at 18:24





    Which separator?

    – forpas
    Jan 1 at 18:24













    thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

    – luca ditrimma
    Jan 1 at 18:33







    thanks forpas, how to get John Doe at 0, 13 at 1 and Subjects at 2? I assume the field is separated by comma.

    – luca ditrimma
    Jan 1 at 18:33















    See my edited answer

    – forpas
    Jan 1 at 18:40





    See my edited answer

    – forpas
    Jan 1 at 18:40













    Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

    – luca ditrimma
    Jan 1 at 18:51





    Your solution worked. But, is there any other solution which use comma as separator and consider double quote as one grouped value?

    – luca ditrimma
    Jan 1 at 18:51











    1














    I'd recommend not doing the parsing yourself, but using an existing library.  (For example, I found Apache Commons CSV easy to use from Kotlin.)



    Although writing parsing code can be fun, and CSV seems simple enough, it has enough complications and variations that unless you created it yourself, you're likely to miss some cases.  (Not just escaped quotes, but other escaped characters, nested quotes, fields which include newlines, comment lines…  And my favourite gotcha: MS Excel uses the machine's list separator, which can be semicolon or another character instead of comma to separate fields!)



    Trust me, I've been there…






    share|improve this answer
























    • this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

      – luca ditrimma
      Jan 1 at 23:59
















    1














    I'd recommend not doing the parsing yourself, but using an existing library.  (For example, I found Apache Commons CSV easy to use from Kotlin.)



    Although writing parsing code can be fun, and CSV seems simple enough, it has enough complications and variations that unless you created it yourself, you're likely to miss some cases.  (Not just escaped quotes, but other escaped characters, nested quotes, fields which include newlines, comment lines…  And my favourite gotcha: MS Excel uses the machine's list separator, which can be semicolon or another character instead of comma to separate fields!)



    Trust me, I've been there…






    share|improve this answer
























    • this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

      – luca ditrimma
      Jan 1 at 23:59














    1












    1








    1







    I'd recommend not doing the parsing yourself, but using an existing library.  (For example, I found Apache Commons CSV easy to use from Kotlin.)



    Although writing parsing code can be fun, and CSV seems simple enough, it has enough complications and variations that unless you created it yourself, you're likely to miss some cases.  (Not just escaped quotes, but other escaped characters, nested quotes, fields which include newlines, comment lines…  And my favourite gotcha: MS Excel uses the machine's list separator, which can be semicolon or another character instead of comma to separate fields!)



    Trust me, I've been there…






    share|improve this answer













    I'd recommend not doing the parsing yourself, but using an existing library.  (For example, I found Apache Commons CSV easy to use from Kotlin.)



    Although writing parsing code can be fun, and CSV seems simple enough, it has enough complications and variations that unless you created it yourself, you're likely to miss some cases.  (Not just escaped quotes, but other escaped characters, nested quotes, fields which include newlines, comment lines…  And my favourite gotcha: MS Excel uses the machine's list separator, which can be semicolon or another character instead of comma to separate fields!)



    Trust me, I've been there…







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 1 at 21:41









    giddsgidds

    1,093127




    1,093127













    • this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

      – luca ditrimma
      Jan 1 at 23:59



















    • this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

      – luca ditrimma
      Jan 1 at 23:59

















    this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

    – luca ditrimma
    Jan 1 at 23:59





    this csv is created by me from another app. :-) Btw, I will give a look on your suggestion for future upgrade.

    – luca ditrimma
    Jan 1 at 23:59











    1














    Is this helpful? Not much of a test since I make no actual assertions, but maybe enough to put you onto the idea.



    @Test
    fun should_tolerate_quoted_commas_in_third_column() {
    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val pattern = Pattern.compile(",")
    s.split(regex=pattern, limit=3).forEach( System.out::println )
    }


    output:



    John Doe
    13
    "Subject 1, Subject 2, Subject 3"


    EDIT 1:



    Similarly...



    @Test
    fun should_make_list_from_quoted_string_in_third_column() {
    val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
    val outerList = s.split(regex = Pattern.compile(","), limit = 3)
    outerList[2].replace(""","").split(",").forEach( System.out::println )
    }





    share|improve this answer






























      1














      Is this helpful? Not much of a test since I make no actual assertions, but maybe enough to put you onto the idea.



      @Test
      fun should_tolerate_quoted_commas_in_third_column() {
      val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
      val pattern = Pattern.compile(",")
      s.split(regex=pattern, limit=3).forEach( System.out::println )
      }


      output:



      John Doe
      13
      "Subject 1, Subject 2, Subject 3"


      EDIT 1:



      Similarly...



      @Test
      fun should_make_list_from_quoted_string_in_third_column() {
      val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
      val outerList = s.split(regex = Pattern.compile(","), limit = 3)
      outerList[2].replace(""","").split(",").forEach( System.out::println )
      }





      share|improve this answer




























        1












        1








        1







        Is this helpful? Not much of a test since I make no actual assertions, but maybe enough to put you onto the idea.



        @Test
        fun should_tolerate_quoted_commas_in_third_column() {
        val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
        val pattern = Pattern.compile(",")
        s.split(regex=pattern, limit=3).forEach( System.out::println )
        }


        output:



        John Doe
        13
        "Subject 1, Subject 2, Subject 3"


        EDIT 1:



        Similarly...



        @Test
        fun should_make_list_from_quoted_string_in_third_column() {
        val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
        val outerList = s.split(regex = Pattern.compile(","), limit = 3)
        outerList[2].replace(""","").split(",").forEach( System.out::println )
        }





        share|improve this answer















        Is this helpful? Not much of a test since I make no actual assertions, but maybe enough to put you onto the idea.



        @Test
        fun should_tolerate_quoted_commas_in_third_column() {
        val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
        val pattern = Pattern.compile(",")
        s.split(regex=pattern, limit=3).forEach( System.out::println )
        }


        output:



        John Doe
        13
        "Subject 1, Subject 2, Subject 3"


        EDIT 1:



        Similarly...



        @Test
        fun should_make_list_from_quoted_string_in_third_column() {
        val s = "John Doe, 13, "Subject 1, Subject 2, Subject 3""
        val outerList = s.split(regex = Pattern.compile(","), limit = 3)
        outerList[2].replace(""","").split(",").forEach( System.out::println )
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 1 at 22:11

























        answered Jan 1 at 19:25









        unigeekunigeek

        1,7021419




        1,7021419






























            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%2f53997728%2fparse-csv-to-kotlin-list%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

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules