1

サーバーからのデータは、ListBox. 以下は私のコードです。

private void button1_Click_2(object sender, EventArgs e)
        {
            //String[] arr = new String[1];
            listBox1.Items.Clear();

            listBox1.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());
            for (int i=0; i <= _server.Q.NoOfItem - 1; i++)
            {
                listBox1.Items.Add( _server.Q.ElementAtBuffer(i).ToString());               
            }

            listBox2.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());
            for (int i = 0; i <= _server.Q.NoOfItem - 1; i++)
            {
                String words = _server.Q.ElementAtBuffer(i).ToString();               
                listBox2.Items.Add(words.Split(new char[] { '[' , ']', ' '}));                
            }

listBox1サーバーから取得したすべてのデータを表示する必要があります。 listBox2分割されたデータを表示することになっています。

これはどのように行うことができますか?

4

4 に答える 4

0

正規表現を使ってみてください:

var pattern = @"\[(.*?)\]"; 
var matches = Regex.Matches(words, pattern);  
foreach (Match m in matches)
{  
   listBox2.Items.Add(/* Add matched item */);
}
于 2012-06-27T05:38:30.310 に答える
0

これはうまくいくはずです:

    private void button1_Click_2(object sender, EventArgs e)
    {
        //String[] arr = new String[1];
        listBox1.Items.Clear();

        listBox1.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());
        for (int i=0; i <= _server.Q.NoOfItem - 1; i++)
        {
            listBox1.Items.Add( _server.Q.ElementAtBuffer(i).ToString());               
        }

        String words = _server.Q.ElementAtBuffer(i).ToString();  
        listBox2.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());
        listBox2.Items.AddRange(words.Split(new char[] { '[' , ']', ' '}));           
    }     
于 2012-06-26T09:33:19.270 に答える
0
    listBox1.Items.Clear();

    listBox1.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());
    listBox2.Items.Add("No Of Items=" + _server.Q.NoOfItem.ToString());

    for (int i = 0; i <= _server.Q.NoOfItem - 1; i++)
    {
        listBox1.Items.Add(_server.Q.ElementAtBuffer(i).ToString());

        String words = _server.Q.ElementAtBuffer(i).ToString();
        string[] arr = words.Split(new char[] { '[', ']', ' ' });
        foreach (string word in arr)
            listBox2.Items.Add(word);
    }
于 2012-06-26T09:38:26.287 に答える
-1
string[] strArray = words.Split(new char[] { '[' , ']', ' '})
for(int x = 0; x < strArray.Count; x++)
{listBox2.Items.Add(strArray[x]}

単語を分割してリストボックスを追加したいと思います 2

于 2012-06-26T09:36:25.283 に答える