Asp.net 在vb中读取csv时如何跳过第一行
我有这个代码片段,它工作正常,但现在在csv文件中,我需要在第一行添加一些信息,因此我需要跳过第一行,如何做到这一点请帮助csv的屏幕截图附在附件中在开始处理行之前,您只需使用Asp.net 在vb中读取csv时如何跳过第一行,asp.net,vb.net,Asp.net,Vb.net,我有这个代码片段,它工作正常,但现在在csv文件中,我需要在第一行添加一些信息,因此我需要跳过第一行,如何做到这一点请帮助csv的屏幕截图附在附件中在开始处理行之前,您只需使用ReadLine一次即可: Try If Not MyCache.GetInstance.AzureCacheOn Then reader = New IO.StreamReader(FilePathUtility.GetInstance.MapPath(objU
ReadLine
一次即可:
Try
If Not MyCache.GetInstance.AzureCacheOn Then
reader = New IO.StreamReader(FilePathUtility.GetInstance.MapPath(objUrl))
Else
request = System.Net.HttpWebRequest.Create(objUrl)
response = DirectCast(request.GetResponse, System.Net.HttpWebResponse)
strm = DirectCast(response.GetResponseStream, IO.Stream)
reader = New IO.StreamReader(strm)
End If
Dim list = New List(Of String)()
Using reader
Dim line As String
While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
list.Add(line)
End While
End Using
lines = list.ToArray()
Catch ex As Exception
Throw ex
End Try
Private Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
在while之前调用read line,同时检查该行是否为空,然后只转到循环。 这将跳过您的第一行 代码如下:
Using reader
reader.ReadLine())
Dim line As String
While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
list.Add(line)
End While
End Using
要跳过第n行(在您的情况下为第2行),请使用:
如果您以前调用reader.ReadLine()一次会发生什么情况?@Yvette c#也会有帮助我会在vbSry中更改大约nxt时间它不会工作,但我需要该标题抱歉,我必须只询问第二行检查更新的代码,现在您可以跳过任何您想要的行(0表示第一行,以此类推)
Using reader
Dim line As String
// if reader.ReadLine() is not empty
While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
list.Add(line)
End While
// end if
End Using
Using reader
Dim line As String
// count = 0, n = 1 // 0 = first line, 1 = 2nd line etc
While (InlineAssignHelper(line, reader.ReadLine())) IsNot Nothing
// if(count++ != n)
list.Add(line)
// end if
End While
End Using