Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,943 questions

51,883 answers

573 users

How to break string to sentences in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            String s = "C# is a multi-paradigm programming language. " +
                       "Strong typing, functional, " +
                       "component-oriented, generic, object-oriented. " +
                       "C# is a general-purpose, " +
                       "object-oriented programming language.";
            var sentences = new List<String>();
            int pos = 0, start = 0;
            do
            {
                pos = s.IndexOf('.', start);
                if (pos >= 0) {
                    sentences.Add(s.Substring(start, pos - start + 1).Trim());
                    start = pos + 1;
                }
            } while (pos > 0);

            foreach (var sentence in sentences)
                Console.WriteLine(sentence);
        }
   }
}


/*
run:

C# is a multi-paradigm programming language.
Strong typing, functional, component-oriented, generic, object-oriented.
C# is a general-purpose, object-oriented programming language.

*/

 



answered Jul 26, 2018 by avibootz
...