skip to Main Content

I had to split string data based on Comma.

This is the excel data:-
Please find the excel data

string strCurrentLine=””Himalayan Salt Body Scrub with Lychee Essential Oil from Majestic Pure, All Natural Scrub to Exfoliate & Moisturize Skin, 12 oz”,SKU_27,”Tombow Dual Brush Pen Art Markers, Portrait, 6-Pack”,SKU_27,My Shopify Store 1,Valid,NonInventory”.

Regex CSVParser = new Regex(“,(?=(?:[^”]“[^”]“)(?![^”]“))”);
string[] lstColumnValues = CSVParser.Split(strCurrentLine);

I have attached the image.The problem is I used the Regex to split the string with comma but i need the ouptut just like SKU_27 because string[0] and string2 contains the forward and backward slash.I need the output string1 and remove the forward and backward slash.

2

Answers


  1. The file seems to be a CVA file. For CVA to be properly formatted, it will use quotes “” to wrap strings that contains comma, such as

    id, name, date
    1,”Some text, that includes comma”, 2020/01/01

    Simply split the string by comma, you will get the 2nd column with double quote.

    Login or Signup to reply.
  2. I’m not sure whether you are asking how to remove the double-quotes from lstColumnValues[0] and lstColumnValues[2], or add them to lstColumnValues[1].

    To remove the double-quotes, just use Replace:

    string myString = lstColumnValues[0].Replace(""", "");
    

    If you need to add them:

    string myString = $""{lstColumnValues[1]}"";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search