I have looked online for many solutions to my problem. I want to ask the user to input a sentence and write the sentence out one word per line using the split method. I have ask
You are currently splitting by a comma ,
only when you need to split by punctuations that may exist in a sentence like space " "
comma ","
and peroid "."
//..other code
string[] split = sentenceTwo.Split(new char[]{' ', '.', ','}, System.StringSplitOptions.RemoveEmptyEntries);
foreach (string item in split)
{
Console.WriteLine(item);
}
//..other code
You should split the string on space instead of on comma:
namespace Seperation
{
class Program
{
static void Main()
{
string temp;
string sentenceTwo = (" ");
Console.WriteLine("please enter a sentence");
temp = Console.ReadLine();
sentenceTwo = temp;
string[] split = sentenceTwo.Split(' ');
foreach (string item in split)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
}