0

I am trying to assign values to the strings in a comma separated string. See incorrect code below.

Dim newArray As String() = "M2-1_,IR,Pass,499V,>10G,5.0s"
results = Split(newArray, ",", -1, vbBinaryCompare)
Dim results1 As String = newArray(0)
Dim results2 As String = newArray(1)
Dim results3 As String = newArray(2)
ListBox1.Items.Add(results1)
ListBox1.Items.Add(results2)
ListBox1.Items.Add(results3)

My current results are:

M    
2    
-

I would like the results:

M2-1_
IR
Pass

Thanks!!!!!

3 Answers 3

2

If you want just the first 3:

    Dim newArray As String = "M2 - 1_,IR,Pass,499V,>10G,5.0s"
    ListBox1.Items.AddRange(newArray.Split(",").Take(3).ToArray)

If you want them all:

    Dim newArray As String = "M2 - 1_,IR,Pass,499V,>10G,5.0s"
    ListBox1.Items.AddRange(newArray.Split(","))
Sign up to request clarification or add additional context in comments.

Comments

0
  Dim newArray = "M2-1_,IR,Pass,499V,>10G,5.0s"
  Dim results() As String = newArray.Split(",")
  ListBox1.Items.Add(results1(0))
  ListBox1.Items.Add(results2(1))
  ListBox1.Items.Add(results3(2))

Comments

0

Your code works if you index into the results array when adding to the ListBox.

Dim newArray As String = "M2-1_,IR,Pass,499V,>10G,5.0s"
Dim results() = Split(newArray, ",", -1, vbBinaryCompare)
ListBox1.Items.Add(results(0))
ListBox1.Items.Add(results(1))
ListBox1.Items.Add(results(2))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.