VB.net 如何从 streamReader.readline.split() 中删除引号字符
VB.net How to remove quotes characters from a streamReader.readline.split()
我建立了一个从报告中读取数据的项目,它过去工作正常,但现在出于某种原因,报告将所有内容都放入了字符串中。所以我想修改我的流 reader 以在它读取行时删除或忽略引号。
这是朗读台词部分的片段。
Dim RawEntList As New List(Of Array)()
Dim newline() As String
Dim CurrentAccountName As String
Dim CurrentAccount As Account
Dim AccountNameExsists As Boolean
Dim NewAccount As Account
Dim NewEntry As Entrey
Dim WrongFileErrorTrigger As String
ListOfLoadedAccountNames.Clear()
'opens the file
Try
Dim sr As New IO.StreamReader(File1Loc)
Console.WriteLine("Loading full report please waite")
MsgBox("Loading full report may take a while.")
'While we have not finished reading the file
While (Not sr.EndOfStream)
'spliting eatch line up into an array
newline = sr.ReadLine.Split(","c)
'storring eatch array into a list
RawEntList.Add(newline)
End While
然后我当然会遍历列表以提取信息来填充对象,如下所示:
For Each Entr In RawEntList
CurrentAccountName = Entr(36)
AccountNameExsists = False
For Each AccountName In ListOfLoadedAccountNames
If CurrentAccountName = AccountName Then
AccountNameExsists = True
End If
Next
你可以这样做
StringName.Replace(ControlChars.Quote, "")
或
StringName.Replace(Chr(34), "")
或
streamReader.readline.split().Replace(Chr(34), "")
在拆分之前,在读取行之后进行替换怎么样?这应该可以节省迭代乘法,或者更好的是(如果可能的话),使用 File 对象的 ReadAllText 方法对整个文件进行替换(如果数据按照可以完成的方式格式化并且您有足够的内存),做你的替换,然后从内存中读取行来构建你的数组(超级快!)。
File.ReadAllText(路径)
我建立了一个从报告中读取数据的项目,它过去工作正常,但现在出于某种原因,报告将所有内容都放入了字符串中。所以我想修改我的流 reader 以在它读取行时删除或忽略引号。
这是朗读台词部分的片段。
Dim RawEntList As New List(Of Array)()
Dim newline() As String
Dim CurrentAccountName As String
Dim CurrentAccount As Account
Dim AccountNameExsists As Boolean
Dim NewAccount As Account
Dim NewEntry As Entrey
Dim WrongFileErrorTrigger As String
ListOfLoadedAccountNames.Clear()
'opens the file
Try
Dim sr As New IO.StreamReader(File1Loc)
Console.WriteLine("Loading full report please waite")
MsgBox("Loading full report may take a while.")
'While we have not finished reading the file
While (Not sr.EndOfStream)
'spliting eatch line up into an array
newline = sr.ReadLine.Split(","c)
'storring eatch array into a list
RawEntList.Add(newline)
End While
然后我当然会遍历列表以提取信息来填充对象,如下所示:
For Each Entr In RawEntList
CurrentAccountName = Entr(36)
AccountNameExsists = False
For Each AccountName In ListOfLoadedAccountNames
If CurrentAccountName = AccountName Then
AccountNameExsists = True
End If
Next
你可以这样做
StringName.Replace(ControlChars.Quote, "")
或
StringName.Replace(Chr(34), "")
或
streamReader.readline.split().Replace(Chr(34), "")
在拆分之前,在读取行之后进行替换怎么样?这应该可以节省迭代乘法,或者更好的是(如果可能的话),使用 File 对象的 ReadAllText 方法对整个文件进行替换(如果数据按照可以完成的方式格式化并且您有足够的内存),做你的替换,然后从内存中读取行来构建你的数组(超级快!)。
File.ReadAllText(路径)