[C#] Split TextBox Text
#1

Hey i am lookin for a Methode to Split a textBox Text Example the Code that HateMe gives for ListBox item to TextBox

shows me the Name and the a_user_index from the Chars, but i wanna that it Shows only the a_user_index.

 

 

 

Thats the Code from HateMe :

 

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedIndex != -1)
{

string name = listBox1.SelectedItem.ToString();
textBox1.Text = name;

}
}

 

Here a Screen how it looks:

2

#2


// Splits the string in parts on every occurance of -
string[] splitted = listBox1.Text.Split('-');

string name = splitted[0].Trim();
int id = int.parse(splitted[1].Trim());

 

Ofcourse this will give a problem when there is a character with a - in the name

 

int id = int.parse(splitted[splitted.Length - 1].Trim());

#3
for this i would add the a_user_index as first before the charname and it looks a bit bether



Forum Jump:


Users browsing this thread: 1 Guest(s)