Created
June 3, 2019 14:39
-
-
Save alldevic/3e2b25526ee98527111ee5321d004886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication10 | |
{ | |
internal class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var seps = new[] {'.', '?', '!'}; | |
var sepsIn = new[] {',', '-', ';', '(', ')'}; | |
var savedSentence = string.Empty; | |
var savedSentenceSepsCount = 0; | |
using (var fl = new StreamReader(@"text.txt")) | |
{ | |
var text = new StringBuilder(); | |
while (fl.Peek() >= 0) // '\0' | |
{ | |
var ch = Convert.ToChar(fl.Read()); | |
if (seps.Contains(ch)) | |
{ | |
text.Append(ch); | |
var currentSentence = text.ToString().Trim(); | |
var currentSentenceSepsCount = | |
currentSentence.Split(sepsIn, StringSplitOptions.RemoveEmptyEntries).Length; | |
if (savedSentence == string.Empty) | |
{ | |
savedSentenceSepsCount = currentSentenceSepsCount; | |
savedSentence = currentSentence; | |
} | |
if (currentSentenceSepsCount > savedSentenceSepsCount) | |
{ | |
savedSentenceSepsCount = currentSentenceSepsCount; | |
savedSentence = currentSentence; | |
} | |
text.Clear(); | |
} | |
else | |
{ | |
text.Append(ch); | |
} | |
} | |
} | |
Console.WriteLine(savedSentence); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment