עכשיו התוכנית תתחיל לעבוד אחרי שאני מכניס טקסט ולוחץ פעמיים אנטר ז"א, אני יכול להכניס טקסט מסויים ואז באנטר להתחיל להכניס עוד טקסט בשורה חדשה אבל אם אני נמצא בשורה חדשה ולא מכניס כלום אלא לוחץ אנטר אז אני מקבל את המילים.
לדוגמא אם אני מכניס את הטקסט:
test abcd$rrr.tyu ver
asd dfg
אז אני מקבל את המילים מסודרות ככה:
test
abcd
rrr
tyu
ver
asd
dfg
התחלתי לכתוב משהו אבל אני מסתבך:
קוד: בחירת הכל
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrintWordWordFromText
{
class Program
{
static void Main(string[] args)
{
//define temp
string temp = "";
int WordIndex = 0;
//read text from user
Console.Write("Enter Text: ");
string line = Console.ReadLine();
//define array
string[] Words = new string[100];
while (line.Length != 0)
{
for (int i = 0; i < line.Length; i++)
{
//We have a regular character - part of a word
if (line[i] != ' ' & line[i] != ' ' & line[i] != ',' & line[i] != '.' & line[i] != '$')
{
temp += line[i];
}
//special characters
else
{
Words[WordIndex] = temp;
WordIndex++;
temp = "";
}
}
}
for (int i = 0; i < WordIndex; i++)
{
Console.Write(Words[i]);
}
Console.ReadLine();
}
}
}

