Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert an array to string

Tags:

arrays

string

c#

How do I make this output to a string?

List<string> Client = new List<string>(); foreach (string listitem in lbClients.SelectedItems) {     Client.Add(listitem); } 
like image 574
Rob Avatar asked Nov 17 '12 00:11

Rob


People also ask

Which method converts an array to string?

JavaScript Array toString() The toString() method returns a string with array values separated by commas.

How do I convert an array of numbers to strings?

To convert an array of numbers to an array of strings, call the map() method on the array, and on each iteration, convert the number to a string. The map method will return a new array containing only strings.

Can we convert string [] to string?

So how to convert String array to String in java. We can use Arrays. toString method that invoke the toString() method on individual elements and use StringBuilder to create String. We can also create our own method to convert String array to String if we have some specific format requirements.


2 Answers

You can join your array using the following:

string.Join(",", Client); 

Then you can output anyway you want. You can change the comma to what ever you want, a space, a pipe, or whatever.

like image 188
CodeLikeBeaker Avatar answered Nov 09 '22 16:11

CodeLikeBeaker


You probably want something like this overload of String.Join:

String.Join<T> Method (String, IEnumerable<T>)

Docs:

http://msdn.microsoft.com/en-us/library/dd992421.aspx

In your example, you'd use

String.Join("", Client);

like image 30
adv12 Avatar answered Nov 09 '22 17:11

adv12