User input then split string

前端 未结 2 388
野性不改
野性不改 2021-01-27 05:55

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

2条回答
  •  执笔经年
    2021-01-27 06:28

    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
    

提交回复
热议问题