0

Hello, I Got problem in using delimiter by using vb.net 2008
Please take a look at my code

Dim array As String()
            Dim IPaddr as String
            Dim r As New System.IO.StreamReader("config.ini")
            Dim rline As String = ""
            Dim s As String = ""
            While r.Peek <> -1
                rline = r.ReadLine()
                array = rline.Split("=")
                if array(0) = "IP Address" then IPaddr = array(1)
            End While
            MsgBox("This is Host IP : " & HostIp)
            MsgBox("This is Port : " & Port)

            r.Close()

The problem is, why I cannot get the array(0) and array(1) values ?

actually before I'm using If, I thought that it can store as many array as the data have but then, it only can store 2 array. So, I decided to use if statement since my config.ini will only have about 5 lines but then I cannot get the array(1) value.

Anyone how what's wrong with my code ?

Thanks

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by codeorder
0

can you please post your sample config.ini?
it looks like you overwrite the array on each line reading and last line is maybe not the format you looking for.

0

Ok, This is what inside my config.ini

HostIP = 127.0.0.1
Port = 1234

Currently two because still testing.

Anyway I'm still trying to fix my code.. see my latest code

Dim array() As String
            Dim storedatas() As String
            Dim i As Integer = 0
            Dim r As New System.IO.StreamReader("config.ini")
            Dim rline As String = ""
            While r.Peek <> -1
                rline = r.ReadLine()
                array = rline.Split("=")
                For Each datas As String In array
                    storedatas(i) = datas
                    i = i + 1
                    MsgBox(storedatas(i))
                Next
            End While

Got some error ini storedatas(i) = datas
Confuse hahaha...

Thanks

0

See if this helps.

Dim myCoolFileLines() As String = IO.File.ReadAllLines("C:\config.ini") '// load your file as a string array.
        Dim array() As String = {""}
        '// go thru each line.
        For Each rLine As String In myCoolFileLines
            array = rLine.Split("=")
            For i As Integer = 0 To array.Length - 1
                MsgBox(array(i))
            Next
        Next

        '// get a single line.
        array = myCoolFileLines(1).Split("=") '// line 2.
        MsgBox(array(0))
        MsgBox(array(1))

Edited by codeorder: slight code change.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.