简体   繁体   English

使用 VB.Net 读取/排序文件

[英]Reading / Sorting a File using VB.Net

I have a project to read and sort a file:我有一个项目来读取和排序文件:

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

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).我正在使用 VB.Net,我想读取这个文件,根据特定条件从每行中提取一些数字(例如,从每行中提取最后/前 17 位数字)。 i read the file using system.io.file.readalllines.我使用 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..但 output 仅显示最后一行的 substring ..

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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