• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1137
  • Last Modified:

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.
0
DTRON04
Asked:
DTRON04
3 Solutions
 
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
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now