Skip to content

Instantly share code, notes, and snippets.

@igorLisovitskiy
Created February 12, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorLisovitskiy/d2e0e759a2e0666e1deec5b192570d08 to your computer and use it in GitHub Desktop.
Save igorLisovitskiy/d2e0e759a2e0666e1deec5b192570d08 to your computer and use it in GitHub Desktop.
using System;
namespace ReadConsole
{
class Program
{
public static void Print1DArrayOfNumbers(int[] arr)
{
foreach (int el in arr)
{
Console.Write($"{el} ");
}
Console.WriteLine();
}
public static string[] SplitBySpace(string text) {
string[] temp = new string[text.Length];
string value = "";
int count = 0;
for (int i = 0; i < text.Length; i++)
{
if (text[i] != 32)
{
value += text[i];
}
if (text[i] == 32 && value != "" || i == text.Length -1)
{
count++;
temp[i] = value;
value = "";
}
}
string[] result = new string[count];
count = 0;
for (int j = 0; j < temp.Length; j++) {
if (temp[j] != null) {
result[count] = temp[j];
count++;
}
}
return result;
}
static void Main(string[] args)
{
string result = "";
while (true)
{
string userInput = Console.ReadLine();
if (userInput == "")
{
Console.WriteLine("Done.");
break;
}
result += " " + userInput;
}
string[] splitInput = SplitBySpace(result);
int[] convertedInput = new int[splitInput.Length];
for (int i = 0; i < splitInput.Length; i++)
{
convertedInput[i] = Convert.ToInt32(splitInput[i]);
}
Console.WriteLine("Your input:");
Print1DArrayOfNumbers(convertedInput);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment