首页 > 编程知识 正文

C# 统计字符串中大写字母和小写字母的个数

时间:2023-05-04 03:57:58 阅读:281804 作者:2231

2019独角兽企业重金招聘Python工程师标准>>>

static void Main() { int count1 = 0; int count2 = 0; Console.WriteLine("请输入字符串"); string str = Convert.ToString(Console.ReadLine()); char[] chars = str.ToCharArray(); foreach(char num in chars){ if(num>='A' && num<='Z'){ count1++; }else if(num>='a' && num<='z'){ count2++; } } Console.WriteLine("大写个数为:"+count1); Console.WriteLine("小写个数为:" + count2); Console.ReadKey(); }

转载于:https://my.oschina.net/u/3740271/blog/1929870

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。