text to listbox item

Posts 1–11 of 11 · Page 1 of 1
text to listbox item
hi mpgh
i have a question how can i convert each letter in a textbox to a listboxitem?
like this:
For i As Integer = 0 To TextBox1.TextLength - 1
ListBox1.Items.Add(TextBox1.Text(i))
Next
[highlight=vb.net]
ListBox1.Items.AddRange(TextBox1.Text.Select(Funct ion(c) c.ToString()).ToArray())
[/highlight]
thanks but when i make a break it adds 3 items without text to the listbox
i assume by "break" you mean a new line? it does this because windows linebreaks are two chars; the carriage return and the line feed.
yes, i mean new line^^
can i change this somehow, that it makes only one new item?
Remove the newlines from the text before adding it to the listbox.

Something like:
Code:
ListBox1.Items.AddRange(TextBox1.Text.Replace(Environment.NewLine).Select(Function(c) c.ToString()).ToArray())
Quote Originally Posted by Jason View Post
Remove the newlines from the text before adding it to the listbox.

Something like:
Code:
ListBox1.Items.AddRange(TextBox1.Text.Replace(Environment.NewLine).Select(Function(c) c.ToString()).ToArray())
dont work
Quote Originally Posted by Kudi View Post
dont work
He forgot to replace the NewLine with null string:

Code:
ListBox1.Items.AddRange(TextBox1.Text.Replace(Environment.NewLine, "").Select(Function(c) c.ToString()).ToArray())
Quote Originally Posted by Hassan View Post


He forgot to replace the NewLine with null string:

Code:
ListBox1.Items.AddRange(TextBox1.Text.Replace(Environment.NewLine, "").Select(Function(c) c.ToString()).ToArray())
Woopsy
but it aslo adds 2 items for a new line
Posts 1–11 of 11 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?