Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to convert string array to CSV format without using string function?Urgent
Posted
Updated 15-Nov-12 20:40pm
v2
Comments
Nelek 16-Nov-12 4:00am    
Using the word "Urgent" won't help you so much. People here help because they want to and when they can.

1 solution

Three options:
1) Use built in method:
C#
string csv = string.Join(",", myArrayOfStrings);

2) Use Linq method:
C#
string csv = myArrayOfStrings.Aggregate((i, j) => i + "," + j);

3) Use a loop and a StringBuilder.
C#
StringBuilder sb = new StringBuilder();
string sep = "";
foreach (string s in myArrayOfStrings)
   {
   sb.AppendFormat("{0}{1}", sep, s);
   sep = ",";
   }
string csv = sb.ToString();
 
Share this answer
 
Comments
Sandeepkumar potu 16-Nov-12 3:46am    
can u give one more solution without using linq?
OriginalGriff 16-Nov-12 3:58am    
Oh come on! I have given you three different approaches! How many do you want?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900