LCKB
[C#] Split TextBox Text - Printable Version

+- LCKB (https://lckb.dev/forum)
+-- Forum: ** OLD LCKB DATABASE ** (https://lckb.dev/forum/forumdisplay.php?fid=109)
+--- Forum: Programmers Gateway (https://lckb.dev/forum/forumdisplay.php?fid=196)
+---- Forum: Coders Talk (https://lckb.dev/forum/forumdisplay.php?fid=192)
+---- Thread: [C#] Split TextBox Text (/showthread.php?tid=1094)



- Nikolee - 09-08-2012


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




- Wizatek - 09-08-2012



// 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());




- HateMe - 09-08-2012

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