Advertisement
OIQ

Untitled

OIQ
Oct 20th, 2020
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4.  
  5. partial class Program
  6. {
  7.     private static readonly string[] Separators = {" ", ". ", ", ", "? ", "! ", ": ", "; "};
  8.  
  9.     private static void CountInFile(string filePath, out int linesCount, out int wordsCount, out int charsCount)
  10.     {
  11.         wordsCount = 0;
  12.         charsCount = 0;
  13.  
  14.         string text = File.ReadAllText(filePath);
  15.         linesCount = File.ReadAllLines(filePath).Length;
  16.  
  17.         string words = text.Replace(". ", " ").Replace(", ", " ").Replace("? ", " ").Replace("! ", " ").Replace(": ", " ").Replace("\r\n", " ").Replace('\n', ' ');
  18.  
  19.         while (words.Contains("  ")) { words = words.Replace("  ", " "); }
  20.  
  21.         wordsCount = words.Trim().Split(' ').Length;
  22.  
  23.         foreach (var line in File.ReadAllLines(filePath))
  24.             charsCount += line.Length;
  25.        
  26.  
  27.        
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement