Looping a Split Array

I need the proper code to loop a Split Array

        Dim BSplit
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")

I want to split the above then loop through the array 0 1 etc.
Could someone help me out with this.
DTRON04Asked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
There are two basic ways to iterate though an array...either by Index or with a For Each loop:

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        Dim value As String
        Dim values() As String

        values = Split("Testing the Split", " ")

        ' First method
        For i = 0 To values.GetUpperBound(0)
            Debug.WriteLine(values(i))
        Next

        ' Second method
        For Each value In values
            Debug.WriteLine(value)
        Next
    End Sub

~IM
0
 
1209Commented:
       Dim BSplit() as string
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
0
 
1209Commented:
discard the previous one....
        Dim BSplit
        BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
for j as inetegr= 0 to upperbond(bsplit)
next
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
DTRON04Author Commented:
Dim BSplit      
 BSplit = Microsoft.VisualBasic.Split(BName, " ")
        For j = 0 To Upperbound(BSplit)
            BClean = BClean + "+" + BSplit(j)
        Next

This code tells me upperbound has to be declared

0
 
1209Commented:
use this..I guess this would solve the problem

dim BSplit() as string
 BSplit = Microsoft.VisualBasic.Split(BName, " ")
        For j = 0 To Microsoft.VisualBasic.Upperbound(BSplit)
            BClean = BClean + "+" + BSplit(j)
        Next
0
 
KGregCommented:
I agree with idle mind, however I just wanted to add a quick note about performance and the For Each loop..  When you use a For Each loop, an Enumerator object is created behind the scenes.  For this reason, you should avoid For Each, and use the For loop indexing method (ie.  For i = 0 to n  etc.) when complexity/performance is a concern

KGREG
0
 
1209Commented:
i was mentioning it wrong...its UBound and not upperbound....
0
 
AmanBrarCommented:
Hi,
try using this:

 Dim BSplit
 BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")

 For n=0 To (BSplit.length() -1)
    Debug.WriteLine( BSplit(n) )
 Next

hope this helps.
0
 
DTRON04Author Commented:
thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.