Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array.Join in .Net?

Ok, this is a dumb thing that I'm sure I've done dozens of times but for some reason I can't find it.

I have an array... And want to get a string with the contents of that array separated by a delimited...

Where is the .Join() method that I can't find?

(This is .Net 2.0, I don't have any LINQ stuff)

Thank you!

like image 876
Daniel Magliola Avatar asked Jan 27 '09 17:01

Daniel Magliola


People also ask

What is array join ()?

Array.prototype.join() The join() method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.

What does .join do in C#?

In C#, Join() is a string method. This method is used to concatenates the members of a collection or the elements of the specified array, using the specified separator between each member or element.

How do you join strings in VB net?

The "&" operator joins two strings together. Example: Dim String1 As String = "123" Dim String2 As String = "456" Dim String3 As String String3 = String1 & String2 ' Results in "123456". The "+" operator may be used in place of "&".

How do you join an element to an array of strings?

The arr. join() method is used to join the elements of an array into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ).


2 Answers

If you're working with strings, then String.Join is probably what you're looking for.

like image 58
Craig Avatar answered Sep 17 '22 13:09

Craig


It is on the string class

String.Join(",", new string[] {"a", "b", "c"}); 

Edit for ints to string

 int[] integers = new int[] { 1,2,3,4,5 };  String.Join(",", Array.ConvertAll<int, String>(integers, Convert.ToString)); 
like image 27
Bob Avatar answered Sep 19 '22 13:09

Bob