2017-01-09 12 views
0

我試圖插入來自匹配()方法的4個值,一個接一個地插入4個不同的文本框,但無法設法從循環後逃脫將第一個值放入第一個文本框,這將使該值在第一個文本框中逐個出現,然後跳轉到下一個文本框以執行相同操作。這裏是我的代碼:?如何從匹配有或沒有foreach循環得到每個值

 for (int g = 0; g <5; g++) //tried this inside foreach() ; no result 
         { 
           foreach (Match m in mc) 
           { 
            /////each foreach returns 4 value, which then should be feed to textbox13 to 16, one by one. 
            if (g == 1) { textBox13.Text = m.Groups[0].Value; MessageBox.Show(m.Groups[0].Value); continue; } 
            //but continue;'s are not breaking the loop 
             if (g == 2) { textBox14.Text = m.Groups[0].Value; MessageBox.Show(m.Groups[0].Value); continue; } 
             //all four value appears in the first textbox(textBox13), one by one, then jumps to 2nd textbox(textBox14) and does the same w/ the same values 
            ////until the 4th textbox (textbox16)... 

              if (g == 3) { textBox15.Text = m.Groups[0].Value; MessageBox.Show(m.Groups[0].Value); continue; } 

               if (g == 4) 
               { 
                textBox16.Text = m.Groups[0].Value; MessageBox.Show(m.Groups[0].Value); 
                sendrow(); 
                textBox13.Text = ""; 
                textBox14.Text = ""; 
                textBox15.Text = ""; 
                textBox16.Text = ""; 
                g = 0;   // then all textboxes emptied for the next group of 4 values... 
                continue;  //coming from a higher-loop, before the 1st for(), which is NOT shown here. 
            } 
         } 
        } 

我在哪裏犯錯與foreach()循環有這場比賽,我們可以通過它們的索引挑選任何價值的,就像我們用它做它的一個特點。 Groups [index] .Value?

謝謝。

回答

0

這樣做的工作。對不起,請打擾(刪除與其他人無關)

     ICollection<string> mc = Regex.Matches(ztring, @"\d+(\.\d{1,4})?").Cast<Match>() 
        .Select(x => x.Groups[0].Value) 
        .ToList(); 

        foreach (string m in mc) 
        { MessageBox.Show(m); 
         textBox13.Text += Environment.NewLine + m; } 

           for (int f = 0; f < textBox13.Lines.Length+1; f++) 
           { 
            string opn_val= textBox10.Lines[0]; 
            string high_val = textBox10.Lines[1]; 
            string low_val = textBox10.Lines[2]; 
            string close_val = textBox10.Lines[3]; 

            if (f == 1) { MessageBox.Show(textBox10.Lines[0]); } 
            if (f == 2) { MessageBox.Show(textBox10.Lines[1]); } 
            if (f == 3) { MessageBox.Show(textBox10.Lines[2]); } 
            if (f == 4) { MessageBox.Show(textBox10.Lines[3]); } 
           } 
        }