Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a textbox, a listbox and a button on a winforms. I want the user to input some text into the textbox and when I click the button it outputs to the listbox, but I want the text seperated by a comma. For example if I enter Monday, Tuesday, Wednesday into the textbox, I want it to display in the listbox as:

Monday,

Tuesday,

Wednesday

Could anyone help?

I have managed to add the text from the textbox to the listbox but can't work out how to split the text by comma.I know that the Split method is used but unsure how to implement it

Thanks

 private void btnSplit_Click(object sender, EventArgs e)
    {
        listboxListItems.Items.Add(txtboxUserInput.Text);
    }
question from:https://stackoverflow.com/questions/66054922/how-to-split-textbox-text-to-listbox-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
623 views
Welcome To Ask or Share your Answers For Others

1 Answer

how to split the text by comma.

You don't actually want to -

From your spec that seems to demand the comma be in the list box too, and your statement that you will enter "Monday, Tuesday, Wednesday" in the textbox:

listboxListItems.Items.AddRange(
  txtboxUserInput.Text.Split()
);

Split() will split on the spaces.. AddRange takes the array Split returns


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...