Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 循环直到VB.NET文件结束_Arrays_Vb.net - Fatal编程技术网

Arrays 循环直到VB.NET文件结束

Arrays 循环直到VB.NET文件结束,arrays,vb.net,Arrays,Vb.net,我有一个包含一个人的名字、第二个名字和年龄的文件: John, Smith, 35 Andrew, Jacobs, 52 我已经将名字、第二个名字和年龄拆分成数组 因为我知道有两个人(我将数组大小设置为1),所以我使用以下“for”循环: For x = 0 to 1 textbox1.text = textbox1.text + first_name(x) Next 我想将此更改为以下内容: For x = 0 to however long the file is textbox1.te

我有一个包含一个人的名字、第二个名字和年龄的文件:

John, Smith, 35
Andrew, Jacobs, 52
我已经将名字、第二个名字和年龄拆分成数组

因为我知道有两个人(我将数组大小设置为1),所以我使用以下“for”循环:

For x = 0 to 1
textbox1.text = textbox1.text + first_name(x)
Next
我想将此更改为以下内容:

For x = 0 to however long the file is
textbox1.text = textbox1.text + first_name(x)
Next

但是,当我尝试使用0作为name.length的首字母时,它不起作用。

如果您要做的是将以行分隔的文件的内容放入VB字符串数组中,为什么不让该文件告诉您有多少行

比如:


如果要做的是将以行分隔的文件的内容放入VB字符串数组中,为什么不让该文件告诉您有多少行

比如:


如果要做的是将以行分隔的文件的内容放入VB字符串数组中,为什么不让该文件告诉您有多少行

比如:


如果要做的是将以行分隔的文件的内容放入VB字符串数组中,为什么不让该文件告诉您有多少行

比如:


创建一个Person类怎么样?这样就不会有单独的数组了

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))
用法:

    Dim people = ReadPeople("c:\people.txt")

创建一个Person类怎么样?这样就不会有单独的数组了

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))
用法:

    Dim people = ReadPeople("c:\people.txt")

创建一个Person类怎么样?这样就不会有单独的数组了

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))
用法:

    Dim people = ReadPeople("c:\people.txt")

创建一个Person类怎么样?这样就不会有单独的数组了

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))
用法:

    Dim people = ReadPeople("c:\people.txt")

如果我是你,我会把事情尽量简化

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))

如果我是你,我会把事情尽量简化

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))

如果我是你,我会把事情尽量简化

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))

如果我是你,我会把事情尽量简化

试试这个:

Public Class Person
    Public FirstName As String
    Public LastName As String
    Public Age As Integer
End Class

Public Function ReadPeople(filePath As String) As Person()
    Return (From record In IO.File.ReadAllLines(filePath)
            Let Terms = record.Split(","c)
            Select New Person With {.LastName = Terms(0), .FirstName = Terms(1), .Age = CInt(Terms(2))}) _
            .ToArray
End Function
textbox1.Text = _
    String.Join("", File.ReadAllLines("") _
        .Select(Function(x) x.Split(","C)(0).Trim()))


“不起作用”可能意味着很多事情。在中缩小范围以帮助那些试图理解的人。数组是基于零的,结尾是first_name.Length-1您已经知道:
我知道有两个人(我将数组大小设置为1)
在执行first\u name.Length-1时,我得到一个类型为“System.NullReferenceException”的未处理异常。其他信息:对象引用未设置为对象的实例。欢迎使用堆栈溢出!几乎所有NullReference异常都有相同的原因。请参阅以获取有关此方面的帮助。“不起作用”可能意味着很多事情。在中缩小范围以帮助那些试图理解的人。数组是基于零的,结尾是first_name.Length-1您已经知道:
我知道有两个人(我将数组大小设置为1)
在执行first\u name.Length-1时,我得到一个类型为“System.NullReferenceException”的未处理异常。其他信息:对象引用未设置为对象的实例。欢迎使用堆栈溢出!几乎所有NullReference异常都有相同的原因。请参阅以获取有关此方面的帮助。“不起作用”可能意味着很多事情。在中缩小范围以帮助那些试图理解的人。数组是基于零的,结尾是first_name.Length-1您已经知道:
我知道有两个人(我将数组大小设置为1)
在执行first\u name.Length-1时,我得到一个类型为“System.NullReferenceException”的未处理异常。其他信息:对象引用未设置为对象的实例。欢迎使用堆栈溢出!几乎所有NullReference异常都有相同的原因。请参阅以获取有关此方面的帮助。“不起作用”可能意味着很多事情。在中缩小范围以帮助那些试图理解的人。数组是基于零的,结尾是first_name.Length-1您已经知道:
我知道有两个人(我将数组大小设置为1)
在执行first\u name.Length-1时,我得到一个类型为“System.NullReferenceException”的未处理异常。其他信息:对象引用未设置为对象的实例。欢迎使用堆栈溢出!几乎所有NullReference异常都有相同的原因。请参阅以获取此方面的帮助。但是我有3个阵列。您有一个人员列表,每个人都有多个属性(姓名等),对吗?然后循环遍历文件中的行,并对每行执行一些操作。该“某物”可能被拆分为它自己的数组。对于i,整数=0到myArray。长度-1temp=myArray(i)。拆分(“,”)第一个\u名称(i)=临时(0)第二个\u名称(i)=临时(1)年龄(i)=临时(2)i=i+1 NextI重新编写了代码示例,以使用更容易理解的变量名,并包含了一个内部循环,该循环考虑了根据逗号分隔值将行拆分为数组。但是我有3个数组。您有一个人员列表,每个人都有多个属性(名称等),对吗?然后循环遍历文件中的行,并对每行执行一些操作。该“某物”可能被拆分为它自己的数组。对于i,整数=0到myArray。长度-1temp=myArray(i)。拆分(“,”)第一个\u名称(i)=临时(0)第二个\u名称(i)=临时(1)年龄(i)=临时(2)i=i+1 NextI重新编写了代码示例,以使用更容易理解的变量名,并包含了一个内部循环,该循环考虑了根据逗号分隔值将行拆分为数组。但是我有3个数组。您有一个人员列表,每个人都有多个属性(名称等),对吗?然后循环遍历文件中的行,并对每行执行一些操作。该“某物”可能会被拆分为它自己的数组。对于i,整数=0到myArray。Length-1temp=myArray(i)。split(“,”)First_name(i)=temp(0)second_name(i)=temp(1)age(i)=temp(2)i=i+1 NextI重新编写代码示例,以使用更容易理解的variab