RedFlys

Home work - split

Mar 20th, 2022
1,078
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Home_Work
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             string userInput;
  14.             string[] userInputWords;
  15.             char[] separations = { ' ', '.', '!', '?', ','};
  16.             int index = 1;
  17.  
  18.             Console.WriteLine("Введите любую строку: ");
  19.             userInput = Console.ReadLine();
  20.  
  21.             userInputWords = userInput.Split(separations);
  22.  
  23.             Console.WriteLine("\nВаши слова:");
  24.  
  25.             foreach (string word in userInputWords)
  26.             {
  27.                 if (word != "")
  28.                 {
  29.                     Console.WriteLine(index + ". " + word);
  30.  
  31.                     index++;
  32.                 }
  33.             }
  34.  
  35.             Console.ReadKey();
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment