Skip to content

Instantly share code, notes, and snippets.

@alldevic
Created June 3, 2019 14:39
Show Gist options
  • Save alldevic/3e2b25526ee98527111ee5321d004886 to your computer and use it in GitHub Desktop.
Save alldevic/3e2b25526ee98527111ee5321d004886 to your computer and use it in GitHub Desktop.
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