编写一个Windows应用程序,该程序功能为:从本机读取一个文本文件(文件中不包含中文字符和符号),统计文件中字符的个数,“,”个数,“.”个数。并把文件中小写英文字母转化为大写,大写字母转化为小写字母。急!!!!!!
解决方案 »
- 程序运行时提示“内存不能Read”
- DataGridView.Columns.Clear() 会释放 DataGridViewColumn对象所占用的空间吗?
- svhost.exe中出现未处理的Win32异常
- 请教找相关 重写 windows form 控件方面的书籍
- 帮忙求助!如下vb代码如何改成c#?谢谢
- 谁能翻译这两句代码,高分相送.
- COM+事务处理,Web Service,错误,高手请支持。
- 在windows界面里怎么写个时间出来,要可以走动的,DateNow()出来以后是个固定时间
- 如何开发绑定自定义控件?
- 求一个简单的单例代码
- 有没有专门讲述OO思想,OOA,OOD,OOP的书?
- 高分求救c#自动拨号,断开代码
string UpperTemp = string.Empty;
string LowerTemp = string.Empty;
Temp = "aBc";
UpperTemp = Temp.ToUpper();
LowerTemp = Temp.ToLower();
using (StreamReader sr = new StreamReader("文本路径"))
{
string text = sr.ReadToEnd();
int commaCount = 0;
int letterCount = 0;
int dotCount = 0;
StringBuilder sb = new StringBuilder();
foreach (char c in text)
{
if (char.IsLetter(c))
letterCount++;
if (c == ',')
commaCount++;
if (c == '.')
dotCount++;
if (c >= 'a' && c <= 'z')
sb.Append(char.ToUpper(c));
else if (c >= 'A' && c <= 'Z')
sb.Append(char.ToLower(c));
else
sb.Append(c);
}
Console.WriteLine("字母个数为{0}", letterCount);
Console.WriteLine(",个数为{0}", commaCount);
Console.WriteLine(".个数为{0}", dotCount);
Console.WriteLine("改变大小写后内容为:");
Console.WriteLine(sb.ToString());
}
using System;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(args[0]);
string text = sr.ReadToEnd();
string outText = "";
int total = 0;
int dohao = 0;
int juhao = 0;
foreach (char c in text)
{
char newc = c;
switch (c)
{
case ',': dohao++; break;
case '.': juhao++; break;
default:
if (Char.IsLower(c))
{
newc = Char.ToUpper(c);
}
else if (Char.IsUpper(c))
{
newc = Char.ToLower(c);
}
break;
}
total++;
outText += newc;
} Console.WriteLine("总字数:{0}", total);
Console.WriteLine(" ,个数:{0}", dohao);
Console.WriteLine(" .个数:{0}", juhao);
Console.WriteLine("转换后:{0}", outText);
Console.ReadLine();
}
}
}
int count1 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^,]", "").Length;//,的个数
int count2 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^a-z]", "").Length;//小写字母的个数
int count3 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^A-Z]", "").Length;//大写字母的字数
int count4 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^A-Za-z]", "").Length;//字母的个数
int count5 = System.Text.RegularExpressions.Regex.Replace(yourStr, @"[^\d]", "").Length;//数字的个数
..................................