这是该文件的片段,
Year 1 mandatory COM137,Mathematics for Computing,20,2 COM140,Computer Technologies,1-2,20 COM147,Introduction to databases,1-2,20 Year 2 optional COM606 ..... etc
我想从这个读取
的数组COM317,计算数学,20,2,M,Year1
COM140,计算机技术,1-2,20,M,Year1
这是我想要的数组中每个元素的布局,但我不知道怎么做,所以应用程序读取文档,看看当年的第1年商店然后读取强制商店,作为M in a变量,然后我想将它添加到一个数组,然后当它看到第二年它再次开始第二年添加到数组元素而不是..这是我到目前为止所尝试的
Dim arrModules As String()
Dim count As Integer = 0
Dim sr As StreamReader = New StreamReader("datasource.txt")
Dim line = sr.ReadLine() ' get each line and store it
Dim currentYear As Integer
Dim moduleStats As String = ""
Dim modArray As String()
While Not sr.EndOfStream
If line.Contains("Year") Then
currentYear = line
ElseIf line.Contains("mandatory") Then
moduleStats = "M"
ElseIf line.Contains("optional") Then
moduleStats = "O"
ElseIf line.Contains("COM") Then
modArray = sr.ReadLine.Split(",")
MsgBox(modArray)
End If
count += 1
sr.ReadLine()
End While
End
//在这里是我遇到问题的地方我不知道怎么把我需要的所有信息都放到一个数组中的一个特定数组元素中..我想把年份和模块状态添加到数组元素的结尾
答案 0 :(得分:0)
将结果从Split复制到一个新的更大的数组,并添加其他信息。
Dim modArray As String() = {"A", "B", "C"}
Dim finalArray As String() = New String(modArray.Length + 1) {}
Array.Copy(modArray, finalArray, modArray.Length)
finalArray(finalArray.Length - 2) = "M"
finalArray(finalArray.Length - 1) = "Year1"
或者你可以简单地使用
ReDim Preserve modArray(modArray.Length+2)
modArray(modArray.Length - 2) = "M"
modArray(modArray.Length - 1) = "Year1"
答案 1 :(得分:0)
这是Visual Basic,您可以通过这种方式为最后两个元素腾出空间:
Dim i As Integer = modArray.Length
ReDim Preserve modArray((i - 1) + 2)
modArray(i) = moduleStats
modArray(i + 1) = currentYear.ToString()