简体   繁体   中英

Reading / Sorting a File using VB.Net

I have a project to read and sort a file:

1234562343243489897654,876546322348976549876543,8974323467890965436654 2345675432345678996525,457843984164457832445546,6356455644546653544236. . . .

I am using VB.Net, i want to read this file, extract some digits from each line according to certain conditions(like, extract last/first 17 digits from each line). i read the file using system.io.file.readalllines. please help me to extract digits and sort.

my code is

Dim alllines As String = "/Path"
Dim Lines = File.ReadAllLines(alllines)
Dim newline As String = ""

For Each line In Lines
    newline = line.Substring(0, 17)
    Richtextbox1.Text=Richtextbox1.Text + newline
Next

but output shows the substring from the last line only..

this is your code

    Dim MyFile As String = PathToFileString
    Dim Lines = File.ReadAllLines(MyFile)
    Dim newLines As ArrayList = New ArrayList()
    Dim newLine As String = ""

    For Each line In Lines
        newLine = line.Substring(line.Length - 17, 17)
        newLines.Add(newLine)
    Next

    newLines.Sort()

this is your code:

Dim allLines = System.IO.File.ReadAllLines("myFilePath")
Dim lines(allLines.Length - 1) As String
For i = 0 To lines.Length - 1
    lines(i) = allLines(i).Substring(0, 17)
Next
System.Array.Sort(lines)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM