Build sentences by concatenating user input until the user enters one of the termination characters. - CSharp Language Basics

CSharp examples for Language Basics:char

Description

Build sentences by concatenating user input until the user enters one of the termination characters.

Demo Code

using System;//from   w  ww .  ja  v a2  s .  co  m
public class Program
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Each line you enter will be "
      + "added to a sentence until you "
      + "enter EXIT or QUIT");
      string sentence = "";
      for (; ; )
      {
         Console.WriteLine("Enter a string ");
         string line = Console.ReadLine();
         string[] terms = { "EXIT", "exit", "QUIT", "quit" };
         bool quitting = false;
         foreach (string term in terms)
         {
            if (String.Compare(line, term) == 0)
            {
               quitting = true;
            }
         }
         if (quitting == true)
         {
            break;
         }
         sentence = String.Concat(sentence, line);
         Console.WriteLine("\nyou've entered: " + sentence);
      }
      Console.WriteLine("\ntotal sentence:\n" + sentence);
   }
}

Result


Related Tutorials