用C#编写程序,从键盘输入一行字符,分别统计出其中的英文字母,数字和其他字符的个数。

如题所述

string xxx = "fahjfhajfFSADFajsif242fAS#@$@%24";
Regex reg = new Regex(@"\d{1}", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture)
reg.Matches(xxx).Count;//数字有多少个
Regex reg = new Regex("([a-z]|[A-Z]){1}", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
 reg.Matches(xxx).Count;//英文字母有多少个?
//剩下的就是其它了

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-10-11
while (true)
{
string s = Console.ReadLine();
char[] charList=str.ToCharArray();
int YWSum=0;
int SZSum=0;
int otherSum=0;
for(int i=0;i<s.length;i++)
{
if((charList[i]>='a' && charList[i]<'z') || (charList[i]>='A' && charList[i]<Z'))
{
YWSum++;
}
if(charList[i]>='0' && charList[i]<'9'))
{
SZSum++;
}
}
otherSum=s.length-YWSum-SZSum;
}
相似回答