Solved

Looping a Split Array

Posted on 2004-10-26
1,106 Views
Last Modified: 2010-04-24
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
Question by:DTRON04
    9 Comments
     

    Expert Comment

    by:1209
           Dim BSplit() as string
            BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
    0
     

    Expert Comment

    by:1209
    discard the previous one....
            Dim BSplit
            BSplit = Microsoft.VisualBasic.Split(Testing the Split, " ")
    for j as inetegr= 0 to upperbond(bsplit)
    next
    0
     

    Author Comment

    by:DTRON04
    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
     

    Assisted Solution

    by:1209
    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
     
    LVL 85

    Accepted Solution

    by:
    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
     
    LVL 6

    Expert Comment

    by:KGreg
    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
     

    Expert Comment

    by:1209
    i was mentioning it wrong...its UBound and not upperbound....
    0
     
    LVL 2

    Assisted Solution

    by:AmanBrar
    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
     

    Author Comment

    by:DTRON04
    thanks guys
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Cisco Complete Network Certification Training

    If you’re an IT engineer or technician, it's time you take your career to the next level. This elite training bundle is brimming with all of the information you need to learn to sit for Cisco CNNA, CCNP, and CCENT certification exams.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now