Advertisement
voldmaks

Split

May 23rd, 2022
668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 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 Split
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string text = "Хочу работу, хочу деньги. Хочу квартиру и новый комп. Но мечтать не вредно, кхе.";
  14.             char[] deleteableCharacters = {' ', ',', '.'};
  15.  
  16.             Console.WriteLine("Вариант с пробелами:");
  17.             foreach (var word in text.Split(deleteableCharacters))
  18.             {
  19.                 Console.WriteLine(word);
  20.             }
  21.  
  22.             Console.WriteLine("\nВариант без пробелов:");
  23.             foreach (var word in text.Split(deleteableCharacters, StringSplitOptions.RemoveEmptyEntries))
  24.             {
  25.                 Console.WriteLine(word);
  26.             }
  27.         }
  28.     }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement