PDA

View Full Version : کار با رشته ها



water_lily_2012
پنج شنبه 15 مهر 1389, 20:41 عصر
سلام
من رشته ای به این صورت دارم

1. d4 d5
2. c4 e6
3. Nc3 Nf6
4. Nf3 Be7
5. Bg5 Nbd7
6. Rc1 O-O
7. e3 c6
8. Qc2 h6
9. Bh4 Ne4
10. Bxe7 Qxe7
چطور می تونم لیست باکسی به صورت زیر داشته باشم.
d4
d5
c4
e6
Nc3
Nf6
Nf3
Be7
Bg5
Nbd7
و ادامه

mmd2009
پنج شنبه 15 مهر 1389, 21:20 عصر
با سلام

به شکل زیر میتونی :



string strRand =
" d4 d5" +
" c4 e6" +
" Nc3 Nf6" +
" Nf3 Be7" +
" Bg5 Nbd7" +
" Rc1 O-O" +
" e3 c6" +
" Qc2 h6" +
" Bh4 Ne4" +
" Bxe7 Qxe7";

string[] strsplit = new string[] { " " };
string[] arrstrRand = strRand.Split(strsplit, StringSplitOptions.None);

foreach (string strInListBox in arrstrRand)
{
if (!(string.IsNullOrEmpty(strInListBox)))
{
listBox1.Items.Add(strInListBox);
}
}