Get the number of lines, words and characters in a text file

string FileContents = My.Computer.FileSystem.ReadAllText("C:\\Temp\\Temp.TXT");
System.Text.RegularExpressions.MatchCollection LinesFound = System.Text.RegularExpressions.Regex.Matches(FileContents, "\\n");
System.Text.RegularExpressions.MatchCollection WordsFound = System.Text.RegularExpressions.Regex.Matches(FileContents, "\\w+");
ulong NumberOfLines = LinesFound.Count;
ulong NumberOfWords = WordsFound.Count;
ulong NumberOfCharacters = FileContents.Length;

No comments:

Post a Comment