Tuesday, April 13, 2010

VB.NET Importing text file into array

SAMPLE VB.NET CODE: VB.NET Importing text file into array


Imports System.IO


Dim files As String() = _
System.IO.File.ReadAllLines("C:\file.txt")
Dim data As String() = Nothing

For Each file As String In files

data = file.Split(New Char() {"|"c}, _
StringSplitOptions.RemoveEmptyEntries)

For Each value As String In data
       Console.WriteLine(data)
Next

Next



            SIMPLER CODE

            Dim lines() As String = IO.File.ReadAllLines(c:\test.txt) 'change to actual path
            Dim newArray(lines.GetUpperBound(0))
            For x As Integer = 0 To lines.GetUpperBound(0)
                newArray(x) = lines(x)
            Next

No comments:

Post a Comment