How can one break a CSV line into rows in C#?

bbcompent1 66 Reputation points
2022-09-08T13:15:13.793+00:00

Greetings all, got a question. I have a CSV file that has several fields, each of which is a pair. What I wanted to do is take the lines of CSV and break them into individual lines. My raw CSV looks like this.

ID | Email | Course1 | Course1_Percentage | Course1_Completion_Date | Course2 | Course2_Percentage | Course2_Completion_Date | Course3 | Course3_Percentage | Course3_Completion_Date

What I would like to see it be:

(Course1) ID | Email | Course |Percentage
(Course2) ID | Email | Course |Percentage
(Course3) ID | Email | Course |Percentage

Thanks in advance.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,094 questions
{count} votes

Accepted answer
  1. Jack J Jun 24,276 Reputation points Microsoft Vendor
    2022-09-12T07:36:17.05+00:00

    @bbcompent1 , Welcome to Microsoft Q&A, you could parse your json string into JArray and get item from JArray. Then you could convert list of object to the csv file.

    Here is a code example you could refer to.

    code.txt

    Result:

    239968-image.png

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful