Jak usunąć z tekstu dane znaki przed ich zaimportowaniem do ComboBoxa?

0

Mam taki kod, chciałbym aby importowany tekst zanim trafil ComboBoxa był pozbawiony znaków ";" , ">" i "."

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myass As New OpenFileDialog
        myass.Filter = "Text Files (*.txt)|*.txt"
        myass.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
        If myass.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
        Dim myfile As String = myass.FileName
        Try
            ComboBox1.Items.Clear()
            Dim reader As New System.IO.StreamReader(myfile)
            Do While Not reader.EndOfStream
                ComboBox1.Items.Add(reader.ReadLine)
            Loop
            reader.Close()
        Catch ex As Exception
        End Try
        ComboBox1.SelectedIndex = 0
    End Sub

Mam taki kod, chciałbym aby importowany tekst zanim trafil ComboBoxa był pozbawiony znaków ";" , ">" i "."
wiem że do TextBoxów można by bylo użyć coś takiego:

If TextBox1.Text.Contains(";") Then
TextBox1.Text = TextBox1.Text.Replace(";", "")

ale z ComboBoxem tak się nie da, bo tekst musi być zmieniony zanim do niego trafi..

0

A pewnie ze zwykłem stringiem się nie da?

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myass As New OpenFileDialog
        Dim line As String

        myass.Filter = "Text Files (*.txt)|*.txt"
        myass.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
        If myass.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
        Dim myfile As String = myass.FileName
        Try
            ComboBox1.Items.Clear()
            Dim reader As New System.IO.StreamReader(myfile)
            Do While Not reader.EndOfStream
                line = reader.ReadLine.Replace(";", "")
                line = line.Replace(">", "")
                line = line.Replace(".", "")
                ComboBox1.Items.Add(line)
            Loop
            reader.Close()
        Catch ex As Exception
        End Try
        ComboBox1.SelectedIndex = 0
    End Sub

A tu bardziej moim zdaniem zaciemnijąca kod konstrukcja:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myass As New OpenFileDialog

        myass.Filter = "Text Files (*.txt)|*.txt"
        myass.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.Desktop
        If myass.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub
        Dim myfile As String = myass.FileName
        Try
            ComboBox1.Items.Clear()
            Dim reader As New System.IO.StreamReader(myfile)
            Do While Not reader.EndOfStream
                ComboBox1.Items.Add(reader.ReadLine.Replace(";", "").Replace(">", "").Replace(".", ""))
            Loop
            reader.Close()
        Catch ex As Exception
        End Try
        ComboBox1.SelectedIndex = 0
    End Sub

1 użytkowników online, w tym zalogowanych: 0, gości: 1