你如何将文件行拆分成数组? [英] How do you split up lines of files into arrays?

查看:78
本文介绍了你如何将文件行拆分成数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件(附图片)。在每一行上都有一个团队编号,后面跟着该团队的一些信息。我想通过","来分割每一行。和";",进入一个数组。例如:

I have a text file (photo attached). On each line is a team number followed by some info on that line, about that team. I would like each line to be split up, by "," and ";", into an array. For example:


  • file = teamOne数组的第1行,其值为{" team 1"," info"," more info","更多东西"}

我试图写这个 - 在文本文件中有一行 - 即使没有成功(附加)。当然我希望它可以使用几行,但在那里我真的不知道该怎么做。人们一直在告诉我使用列表,但我没有
理解它们。

I tried to write this already - with one line in the text file - even without success (attached). Of course I wish for it to work with several lines, but there I really have no clue as to what to do. People have been telling me to use lists, but I do not understand them.

Module Program
	Sub Main()
	      Dim separators() As String = {",", ".", "!", "?", ";", ":", " "}
	      Dim value As String
	      Dim words() As String = value.Split(separators, StringSplitOptions.RemoveEmptyEntries)
	      Dim fileline As String
	      
	      FileOpen(1, "file.txt", OpenMode.Input)
			
	      Do While Not EOF(1)
		 fileline = LineInput(1)
		 value(fileline)
	      Loop
			
	      FileClose(1)
	      
	      For Each word In words
	         Console.WriteLine(word)
	      Next
	      Console.ReadKey()
	End Sub
End Module


(在控制台中降低复杂性)。

(In console to reduce complexity).

我希望我说得够清楚。谢谢!

I hope I made this clear enough. Thanks!

推荐答案

Bobby,

Bobby,

每行您都会使用以下内容:

Per line you'd use something like this:

Public Class Form1
    Private Sub _
        Form1_Load(sender As System.Object, _
                   e As System.EventArgs) _
                   Handles MyBase.Load

        Dim text As String = "team1;info,more,more stuffs"

        Dim s() As String = text.Split(New Char() {";"c, ","c}, StringSplitOptions.RemoveEmptyEntries)

        Stop

    End Sub
End Class

您可以考虑设置课程照顾所有这些,但我不太了解你的信息。

You might consider setting up a class to take care of all of this but I don't know enough about your information here.


这篇关于你如何将文件行拆分成数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆