How to write a value which contain comma to a CSV file in c#?

前端 未结 6 1371
时光取名叫无心
时光取名叫无心 2021-01-01 14:58

I am using a data table for storing data.

I am exporting the data from data table to CSV file.

Sometimes there may be values containing comma(,)

6条回答
  •  被撕碎了的回忆
    2021-01-01 15:22

    1. Fields with embedded commas must be delimited with double-quote characters.

      fields:

      1. abc, xyz
      2. pqr

    csv version:

    "abc, xyz" , pqr
    
    1. Fields that contain double quote characters must be surounded by double-quotes, and the embedded double-quotes must each be represented by a pair of consecutive double quotes.

      field:

      Welcome to "My World"
      

      csv version:

      "Welcome to ""My World"""
      

提交回复
热议问题