Splitting a string on comma and printing the results

split, string, vb.net

Solution

It is not clear from your question, but if you want only the first word in your array of strings then no need to loop over it

 Dim firstWord = parts(0)
 Console.WriteLine(firstWord) ' Should print `a` from your text sample

 ' or simply
 Console.WriteLine(parts(0)) 

 ' and the second word is     
 Console.WriteLine(parts(1))  ' prints `bc`

Problem

I am using the following code to split a string and retrieve them: ``` Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim s As String = "a,bc,def,ghij,klmno" Dim parts As String() = s.Split(New Char() {","c}) Dim part As String For Each part In parts MsgBox(part(0)) Next End Sub ``` But the message box shows only the first character in each splitted `string (a,b,d,g,k)`. I want to show only the first word, what am I doing wrong?

Original source