I want to create one csv file using C#.
I have some data which I want to write on multiple lines BUT within the same cell.
For example If I have following t
To quote Wikipedia:
Fields with embedded line breaks must be enclosed within double-quote characters.
Like e.g.:
1997,Ford,E350,"Go get one now
they are going fast"
You might be able to change which tokens your application uses to parse rows from the csv file, but according to the definition of the csv file format, lines in the file are used to represent rows in the resulting tabular data.
string input = "...";
var r = input.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries) // split by dot (have you any better approaches?)
.Select(s => String.Format("\"{0}.\"", s.Trim())); // escape each with quotes
input = String.Join(Environment.NewLine, r); // break by line break
CSV stands for "comma seperated values" which is just a description of a text-file. If you want to import into Excel and then only have the sentences in one line you should try:
Environment.NewLine
instread of a simple /n
Always wrap your description in between "\" eg: CsvRow.Add("\"" + ID + " : " + description + "\"");