- 博客(1)
- 资源 (3)
- 收藏
- 关注
转载 检查用户输入代码
using System;namespace Example_6{class DigitLetterPunctuation{ static void Main(string[]args) { int countLetters=0; int countDigits=0; int countPunctuations=0; string input; Console
2008-05-05 00:54:00 332
c#软件经典
using System;<br>namespace Example_6<br>{<br>class DigitLetterPunctuation<br>{<br> static void Main(string[]args)<br> {<br> int countLetters=0;<br> int countDigits=0;<br> int countPunctuations=0;<br> string input;<br> Console.WriteLine("请输入一个字符串");<br> input=Console.ReadLine();<br> foreach(char chr in input)<br> {<br> if(char.IsLetter(chr))<br> countLetters++;<br> if(char.IsDigit(chr))<br> countDigits++;<br> if(char.IsPunctuation(chr))<br> countPunctuations++;<br> }<br> Console.WriteLine("字母的个数为:{0}",countLetters);<br> Console.WriteLine("数字的个数为:{0}",countDigits);<br> Console.WriteLine("字母的个数为:{0}",countPunctuations);<br><br> }<br><br>}<br>} <br><br> void check()<br> {<br> /*<br> * string str = "和";//你要判断的字符 <br> byte[] tmp = System.Text.UnicodeEncoding.Default.GetBytes(str); <br> if(tmp.Length >1) <br> { <br> //字符为汉字 <br> } <br> */<br> string s = numericUpDown1.Value.ToString();<br> int n = 0;<br> foreach (char c in s)<br> {<br> if (c >= 0x4e00 && c <= 0x9fa5)<br> n++;<br> }<br> if (n > 0)<br> {<br> MessageBox.Show("输入为数字");<br> }<br> }<br>
2008-05-05
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人