Split lines from textfile into 2 array's


I want to read lines from a file containing 2 values per line..... example of a line:

LDAP://dc=MyDomain, dc=local;MyDomain

So I read the lines into a string and split the string (on ;) and want to put the splitted values in 2 different array.

This is what I tried:

        Dim i As Integer = 0
        Dim StrLDAP As String() = Nothing
        Dim StrDomainNames As String() = Nothing

        Dim line As String
        For Each line In File.ReadAllLines(appPath & "\domains.ini")
            Dim Strvalues() As String = line.Split(New Char() {";"c})

            StrLDAP(i) = (Strvalues(0))
            StrDomainNames(i) = (Strvalues(1))
            i = i + 1


Open in new window

When I run this code I get the error "Object reference no set to an instance of an object".
I can see the StrValues are containing the splitted data so there must be something wrong with the araray's i'm putting the data in.... but what?

Please help.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Craig WagnerSoftware ArchitectCommented:
Your arrays are never initialized, you declare the variable and set it to Nothing, so your array is a null reference.

Arrays don't dynamically resize so you're going to need to know how many entries the array must hold before you create them. Alternatively you could use a data structure that can be resized, such as a List(Of String). Then on each iteration of the loop you can just .Add(...) to the lists.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.