Reputation: 2032
I have a list of names with scores in lstInput (a listbox) that looks something like this:
Name1,100,200,300
Name2,100,200,300
Name3,100,200,300
...etc...
I need to split the array into a string and print the results of the person's name and the scores that are separated by a comma.
What I have so far is the following:
For s As Integer = 0 To lstInput.Items.Count - 1
lstOutput.Items.Add(lstInput.Items(s))
Next
Now, that displays the entire list, but I need to split the list into strings so that they display on their own: e.g. Name1 100 200 300
...etc..
Upvotes: 0
Views: 9633
Reputation: 26386
For s As Integer = 0 To lstInput.Items.Count - 1
dim items As String() = lstInput.Items(s).Split(",".ToCharArray()) 'splits into array of 4 elements
dim name As String = items(0) 'first element is name
dim score1 As String = items(1) 'second element is first score
-- now do the rest yourself
-- listOutput.Items.Add( concatenate name and the scores here)
Next
Upvotes: 1
Reputation: 26424
I may be going crazy, but I think the OP wants something like this:
For s As Integer = 0 To lstInput.Items.Count - 1
lstOutput.Items.Add(String.Join(" ", CType(lstInput.Items(s), String).Split(",")))
Next
Purpose of this code is unknown but it ultimately removes commas, so this Name1,100,200,300
becomes this Name1 100 200 300
(just following the question). Guess I could have done String.Replace
instead, but it's not as cool.
Upvotes: 2