How to parse string[] to string with spaces in between
How would you refactor this code?
internal string ConvertStringArrayToString(string[] array)
{
StringBuilder builder = new StringBuilder();
builder.Append(array[0]);
for (int i = 1; i < array.Length; i++)
{
builder.Append(' ');
builder.Append(array[i]);
}
return builder.ToString();
}
There is a method for that already:
This will put a space between each element. Note that if any of your elements are empty strings, you’ll end up with spaces adjacent to each other, so you may want to filter those ahead of time, like this: