【发布时间】:2015-01-10 21:15:07
【问题描述】:
我得到了一个用 java 程序创建的文件,但没有 LF 或 endofline 结尾,所以我正在处理一个巨大的字符串。我尝试拆分然后使用 TextFieldParser 但似乎文件太大而无法处理。内容对于我需要以某种方式获取这些数据然后清理它至关重要。这是我尝试过的:
Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\Users\Desktop\META3.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
MsgBox(currentField)
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & "is not valid and will be skipped.")
End Try
End While
End Using
我认为最好的方法是获取文本的子字符串,我想在逗号出现 7 次之后获取所有值,这是文件每行应该包含的值。不知道如何做到这一点,似乎正则表达式可能是唯一的选择。任何想法表示赞赏。
line = freader.Readline()
Dim ms As Match = Regex.Match(line, "(\w+),(\w+),(\w+),(\w+),(\w+),(\w+),")
line = ms.Value
这行得通吗?没有给出预期的结果。
【问题讨论】:
标签: vb.net substring string-split