从txt文件中提取文本

时间:2014-03-18 09:16:19

标签: vb.net

我的txt文件包含许多具有此结构的行:

213008   DOMUS URBAN VILLAS                 09/04/13                    0-0 0 1-1-0                ED ML LC 10 MO PA 03 03    ED

没有制表,只是由生成此文件的第三方软件添加的空格。

有没有办法提取每一段文字?

我的意思是,获得一种方式:

text_1 = 213008
text_2 = DOMUS URBAN VILLAS
text_3 = 09/04/13

2 个答案:

答案 0 :(得分:0)

这对我有用:

        Dim InputText As String = Replace(IO.File.ReadAllText(FileName), "  ", ",") 'two spaces
        Do Until InputText.Contains(",,") = False
            InputText = Replace(InputText, ",,", ",")
        Loop
        Dim Lines() As String = InputText.Split(",")

text_1 = Lines(0)
text_2 = Lines(1)
text_3 = Lines(2)

答案 1 :(得分:0)

您可以使用Microsoft.VisualBasic.FileIO.TextFieldParser来解析文件

中的文字