TheBulgarianWolf

Append Arrays

Dec 14th, 2020
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace AppendArrays
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("This program appends your arrays which are split by | from the last to the first and removes all the whitespaces.");
  11.             Console.WriteLine("Enter your array here: ");
  12.             string unformattedLine = Console.ReadLine();
  13.             string[] arrays = unformattedLine.Split("|");
  14.             string[] formattedArr = new string[arrays.Length];
  15.             string arrayFormatted = "";
  16.             for(int i = arrays.Length-1; i >= 0; i--)
  17.             {
  18.                 formattedArr[i] = arrays[arrays.Length-i-1] + " ";
  19.             }
  20.             formattedArr = formattedArr.Select(l => String.Join(" ", l.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))).ToArray();
  21.  
  22.             foreach(string str in formattedArr)
  23.             {
  24.                 Console.Write(str + " ");
  25.             }
  26.         }
  27.     }
  28. }
  29.  
Add Comment
Please, Sign In to add comment