Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai friends,


How can i get the array values in the label box as a comma seperated format.Plz help me.


Thanks in advance
Posted

Try this sample:


C#
string[] array = { "one", "two", "three" };
       string output = "";
       array.ToList().ForEach(k => output += k + ",");
       label.Text = output.Trim(',');
 
Share this answer
 
Comments
Member 10234093 16-Jan-14 6:42am    
Thanks.I got it.
Karthik_Mahalingam 16-Jan-14 6:57am    
welcome dude :)
C#
//Declare an string Array
           string[] strArray = { "sandeep", "singh", "shekhawat" };

           //declare final resul variable
           string resultText = string.Empty;
           //CSV string using foreach loop
           foreach (string arrayItem in strArray)
           {
               resultText += arrayItem + ",";
           }
           resultText = resultText.Substring(0, resultText.Length - 1);
           //CSV string using Linq to sql join function
           resultText = string.Join(",",strArray);
 
Share this answer
 
Comments
Member 10234093 16-Jan-14 6:51am    
Thank u too
Sandeep Singh Shekhawat 16-Jan-14 6:52am    
Welcome Dear
Karthik_Mahalingam 16-Jan-14 6:59am    
5! Correct..
if he is using some earlier version Dot net. my solution will not work as i am using LINQ
but yours will run in all Framework ..
Good.
Sandeep Singh Shekhawat 16-Jan-14 7:01am    
Thanks Karthik sir..
Karthik_Mahalingam 16-Jan-14 7:14am    
welcome sandeep :)
No Sir and all. I am simple programmer..
Se this Stack Overflow question: Array.ToString()[^].
 
Share this answer
 

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