Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opposite of String.Split with separators (.net)

Is there a way to do the opposite of String.Split in .Net? That is, to combine all the elements of an array with a given separator.

Taking ["a", "b", "c"] and giving "a b c" (with a separator of " ").

UPDATE: I found the answer myself. It is the String.Join method.

like image 238
robintw Avatar asked Jan 18 '09 16:01

robintw


People also ask

Does split mutate the string?

The splitter can be a single character, another string, or a regular expression. After splitting the string into multiple substrings, the split() method puts them in an array and returns it. It doesn't make any modifications to the original string. Let's understand how this works with an example.

How do I split a string into two parts in C#?

In C#, Split() is a string class method. The Split() method returns an array of strings generated by splitting of original string separated by the delimiters passed as a parameter in Split() method. The delimiters can be a character or an array of characters or an array of strings.

Is .split a string method?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.


1 Answers

Found the answer. It's called String.Join.

like image 50
robintw Avatar answered Oct 01 '22 11:10

robintw