c#程序计算文本文件中的字符和行 [英] c# program to count character and lines in text file
本文介绍了c#程序计算文本文件中的字符和行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
如何编写程序来计算c#中文本文件中的单词,字符和行.......
谢谢和问候
Srishti
Hello,
how to write a program to count words ,character and lines in a text file in c#.......
Thanks & Regards
Srishti
推荐答案
试试
http://www.dotnetperls.com/count-characters [ ^ ]
http://en.csharp-online.net/CSharp_Regular_Expression_Recipes%E2%80%94Counting_Lines_of_Text [ ^ ]
在c#中计算文本框中的字符数 [ ^ ]
Try
http://www.dotnetperls.com/count-characters[^]
http://en.csharp-online.net/CSharp_Regular_Expression_Recipes%E2%80%94Counting_Lines_of_Text[^]
Count Characters in Textbox in c#[^]
你也可以尝试这个
You can try this also
int WordsCount = CharCount = LinesCount = 0;
string FilePath = "your file path here";
string FileText = new System.IO.StreamReader(FilePath).ReadToEnd().Replace("\r\n", "\r");
CharCount = FileText.Length; //total char
LinesCount = FileText.Split('\r').Length; //total lines
WordsCount = FileText.Split(' ').Length; // total Words
class Demo
{
public static void Main()
{
string path = File.ReadAllText("D:\\jittu.txt");
Console.WriteLine(path); // it ll display ur file on console
Console.Write(path.Length); // show character
Console.WriteLine();
Console.WriteLine(path.Split('\r').Length); // total line
Console.WriteLine(path.Split(' ').Length); // total word
}
}
这篇关于c#程序计算文本文件中的字符和行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文