编写代码,由用户输入一个字符串,使用foreach循环遍历出此字符串中有多个字母,多少个数字,多少个标点

  foreach (char chr in input)

  {

      //检查字母

      if (char.IsLetter(chr))

      {

    countLetters++;

      }

      //检查数字

      if (char.IsDigit(chr))

      {

    countDigits++;

      }

      //检查标点

      if (char.IsPunctuation(chr))

      {

    countPunctuation++;

      }

  }

posted @ 2011-10-12 11:33  pnljs  阅读(2279)  评论(0编辑  收藏  举报