Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Join Array of string into single string?

Scenario: I have list of Networks Name in Database Table with numbers e.g (1. Facebook, 2. Twitter, 3. MySpace, 4. hi5 ...) and I select one Network from database (e.g 2. Twitter).

What I Did:

string Selected = "12.FaceBook";
int k=3;
string[] myArray = new string[Selected.Length];
for (int i = 0; i < Selected.Length; i++)
{
    myArray[i] = Selected[k].ToString();
    k++;
}

and sucked how to join myArray and print in

DevComponents.DotNetBar.MessageBoxEx.Show("?");

What I Want:

output as:

"Facebook" or "Twitter" without numbers.

like image 758
Saeed Khan Avatar asked Oct 20 '25 01:10

Saeed Khan


1 Answers

This should do it:

string joined = string.Join("", myArray);
DevComponents.DotNetBar.MessageBoxEx.Show(joined);

If you want to put a separator between the joined strings, that's the first parameter of string.Join(). For example, to put a space between them:

string joined = string.Join(" ", myArray);

However, your code to actually create the string array in the first place looks wrong. Do you get a single string back from the database for the required network, or do you get a single string containing all networks that you have to parse yourself?

like image 128
Matthew Watson Avatar answered Oct 21 '25 14:10

Matthew Watson