0

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..

4

2 回答 2

2

我可能要疯了,但我认为 OP 想要这样的东西:

For s As Integer = 0 To lstInput.Items.Count - 1
  lstOutput.Items.Add(String.Join(" ", CType(lstInput.Items(s), String).Split(",")))
Next

这段代码的目的是未知的,但它最终删除了逗号,所以这Name1,100,200,300变成了这个Name1 100 200 300(就在问题之后)。我想我可以这样做String.Replace,但它并不那么酷。

于 2012-11-07T02:20:52.800 回答
1
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
于 2012-11-07T02:15:38.437 回答