IT KNOWLEDGE

IT KNOWLEDGE
BC

Thursday, May 22, 2014

Retrieve each word in a string to list in a listbox

I VB.Net, we can use one method called "Split(space)" to split each word from the sentence or paragraph.
Below is the sample small application use split each word in Textbox to list in Listbox. 


Application Design


No Control Type Name Text
1 TextBox1 TextBoxString
2 ListBoxWord1
3 Button1 ButtonGetWord Get Word


Code
Public Class Split_Word

    Private Sub ButtonGetWord_Click(sender As Object, e As EventArgs) Handles ButtonGetWord.Click
        ListBoxGetWord.Items.Clear()                   ' clear old lists
        Dim words() As String
        Dim space() As Char = {" "c}
        words = TextboxString.Text.Split(space)  ' Split each word which devided by space in TextboxString
        Dim word As String
        For Each word In words
            ListBoxGetWord.Items.Add(word)           list each word in listbox
        Next
    End Sub
End Class




Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: itech-9999

0 comments: