If you really want to split English text by sentences (and not just for a homework exercise), I would recommend the use of one of the open source natural language processing tools, for example SharpNLP which is a C# port of the Java OpenNLP tools. I have downloaded the source code for this from GitHub and created the following example in its Test
project. This program outputs 6 sentences and the longest sentence is actually the first sentence.
using OpenNLP.Tools.SentenceDetect;
namespace Test
{
internal class Program
{
private static readonly string currentDirectory = Environment.CurrentDirectory + "/../../";
private static void Main(string[] args)
{
var inputText =
"C#[note 2] (pronounced as see sharp) is a multi-paradigm programming language encompassing strong typing, imperative, declarative, functional, generic, object-oriented (class-based), and component-oriented programming disciplines. It was developed by Microsoft within its .NET initiative and later approved as a standard by Ecma (ECMA-334) and ISO (ISO/IEC 23270:2006). C# is one of the programming languages designed for the Common Language Infrastructure. C# is intended to be a simple, modern, general-purpose, object-oriented programming language.[7] Its development team is led by Anders Hejlsberg. The most recent version is C# 6.0, which was released on July 20, 2015.[8]";
var sentenceDetector =
new EnglishMaximumEntropySentenceDetector(currentDirectory + "../Resources/Models/EnglishSD.nbin");
string[] sentences = sentenceDetector.SentenceDetect(inputText);
string longest = sentences.OrderByDescending(s => s.Length).First();
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…