在winform中,如何在textbox检查有多少个大写字母,恕我新手!!!求解!!!????winformtextbox

解决方案 »

  1.   

      int count = Regex.Matches(textBox1.Text, "[A-Z]").Count;
                MessageBox.Show("有" + count + "个大写字母");
      

  2.   

    private int i = 0;
    private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
    {
    //大写字母A-Z的ASC码范围是65-90;
    if ((int)e.KeyChar > 65 & (int)e.KeyChar < 90 || (int)e.KeyChar == 8)
    {
    i++;
    }
    MessageBox.Show(i.ToString());
    }
      

  3.   

    int n = textBox1.Text.Where(x => x >= 'A' && x <= 'Z').Count();