Search code examples
vb.netreplacetrimstreamreader

VB.net How to remove quotes characters from a streamReader.readline.split()


I had built a project that read data from a report and it used to work fine but now for some reason the report puts every thing in to strings. So I want to modify my stream reader to remove or ignore the quotes as it reads the lines.

This is a snipet of the part that reads the lines.

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

And then of course I iterate through the list to pull out information to populate objects like this:

For Each Entr In RawEntList
    CurrentAccountName = Entr(36)
    AccountNameExsists = False
    For Each AccountName In ListOfLoadedAccountNames
        If CurrentAccountName = AccountName Then
            AccountNameExsists = True
        End If
    Next

Solution

  • You could just do

    StringName.Replace(ControlChars.Quote, "")
    

    or

    StringName.Replace(Chr(34), "")
    

    OR

    streamReader.readline.split().Replace(Chr(34), "")