Hi again guys :D I need to make a program that reads a txt file, show the original file on a RTB and then show the words of the file, sorted alphabetically with the number of words found on the file in another RTB, e.g.

"That fox killed my rabbit, but my dog killed the fox"


but 1
dog 1
fox 2
killed 2
rabbit 1
That 1
the 1

The program must convert all the strings to minus and eliminate periods , ), (.

The code that i have sort alphabetically, but instead of counting the words count the lines in which the words appear e.g.

but 1
dog 1
fox 1
fox 1
killed 1
killed 1
my 1
my 1
rabbit, 1
That 1
the 1

The part where I need to eliminate ., ), ( etc and convert to minus the words I have it but i don't know how to implement it into the code, so basically the program left the counting of concurrene words and convert all the words to minus and eliminate extra characters.

This is my code, the part that do the sort and need to introduce the changes starts @ line 68 and ends @line 87

Imports System.IO

Public Class Form1

    Private Sub AbrirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AbrirToolStripMenuItem.Click
        Dim myStream As Stream = Nothing

        Dim openFileDialog1 As New OpenFileDialog()
        With openFileDialog1 'dando las características al archivo que abriremos
            .InitialDirectory = "c:\" 'directorio inicial
            .Filter = "Archivos txt (*.txt)|*.txt|Todos los Archivos (*.*)|*.*" 'archivos que podra abrir
            .FilterIndex = 1 'indexe del archivo de lectura por defecto
            .RestoreDirectory = False 'restaurar directorio default al abrir de nuevo
            .Multiselect = False 'cancelando la multiple seleccion
            .Title = "Selecciona un Archivo de Texto" 'titulo de la ventana
        End With
        'si se encontro el archivo
        If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                'abrir el archivo
                myStream = openFileDialog1.OpenFile()
                If (myStream IsNot Nothing) Then 'si no es nulo
                    LoadToRichTextBox(myStream) 'que desamos hacer con el archivo
                End If
            Catch Ex As Exception
                MessageBox.Show("No se puede leer el archivo del disco. Error original: " & Ex.Message)

                'comprobar esto de nuevo, ya que tenemos que asegurarnos de que no se produzca una excepcion cuando este abierto
                If (myStream IsNot Nothing) Then 'si no se escogio nada entonces
                    myStream.Close() 'cerrar el streaming de datos
                End If
            End Try
        End If
    End Sub
    Private Sub GuardarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GuardarToolStripMenuItem.Click

        Dim SaveFileDialog1 As New SaveFileDialog()
        With SaveFileDialog1
            .InitialDirectory = "c:/" 'directorio inicial
            .CheckFileExists = True 'checar primero si el archivo no existe primero
            .CheckPathExists = True 'checar si la ruta de acceso existe
            .Filter = "Archivos txt (*.txt)|*.txt|Todos los Archivos (*.*)|*.*"
            .FilterIndex = "1"
            .RestoreDirectory = False
            .Title = "Guardar Archivo de Texto"
        End With
        ' si la ventana de diaologo esta abierta y el resultado es positivo
        If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim bAppendToFile As Boolean = False
            'se guarda todo el texto, nombre, y de donde se va a guardar
            My.Computer.FileSystem.WriteAllText( _
                SaveFileDialog1.FileName, RichTextBox2.Text, bAppendToFile)
        End If

    End Sub
    Private Sub LoadToRichTextBox(ByVal myStream As Stream)
        Dim myStreamReader As StreamReader = New StreamReader(myStream)

        Me.RichTextBox1.Clear() 'limpiando el RichTextBox
        'hacemos un while para leer de principio a fin el archivo de texto
        While myStreamReader.Peek() >= 0
            Dim str As String = myStreamReader.ReadToEnd
            Me.RichTextBox1.Text = str.ToLower
        End While

    End Sub
    Private Sub TabPage2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage2.VisibleChanged
        'wtf como uso esto
        'rtbString.Replace(".", "")
        'txtString.Replace(".", "")

        Dim WordList As New List(Of String) 'Esto contendra nuestra lista ordenada cuando haya terminado
        For i As Integer = 0 To RichTextBox1.Lines.Count - 1  'recorrer las primeras líneas del RTB

            Dim SeparatedWords() As String = RichTextBox1.Lines(i).Split(" "c)   'dividir las palabras en esta línea hasta

            For Each Word As String In SeparatedWords   'hacemos un bucle a traves de las palabras en esta linea
                WordList.Add(Word & " " & (i + 1))   'añadir cada palabra y el número a nuestra lista 

        WordList.Sort()  'Acomoda alfabeticamente

        RichTextBox2.Lines = WordList.ToArray  'establece el texto de la otroa RTB a nuestra lista de palabras ordenadas
    End Sub
    Private Sub SalirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SalirToolStripMenuItem.Click
        Me.Close() 'cierro forma
    End Sub

    Private Sub AcercaDeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AcercaDeToolStripMenuItem.Click
        AboutBox1.Visible = True 'hago visible la forma sobre...
    End Sub
End Class

Any help will be very appreciated

Thanks in advanced!!

EDIT: I find an easy way to convert from mayus to minus the string words, so the program only left the delete function of characteres and the concurrency of words

i remember that kind of topic was few weeks ago already on that forum. did u use the search function on that site before posting?

yep, i checked first the forums but i didn't find anything like this

wow thx for the urls i really looked before but nothing of this appeared i'll try some examps here, thanks so much 4 ur help.

i'll leave open the thread until i can find the solution

thx again :D

hi again, I find a code thx to GeekByChoiCe that maybe could help me this is the url. I modified it alittle bit, but now I can't get the correct output, this is the code:

Private Sub TabPage2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabPage2.VisibleChanged
        'wtf como uso esto
        'rtbString.Replace(".", "")
        'txtString.Replace(".", "")

        Dim sentence As String = RichTextBox1.Text

        Dim words() As String = System.Text.RegularExpressions.Regex.Split(sentence, "\W+")

        Dim dict As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)

        For Each word In words

            Dim cnt As Integer

            If (dict.TryGetValue(word, cnt)) Then

                dict(word) = cnt + 1


                dict.Add(word, 1)

            End If

        For Each key In dict
            'this doesn't work to sort
             'this doesn't work too, to print the output
            'RichTextBox2.Text = dict.toarray
             'original code to print the output
              Console.WriteLine("Word: {0} Count:{1}", key.Key, key.Value)


    End Sub

if anyone could help with this I'll really aprecciate it

Thanks in advance

well comment the line
Console.WriteLine("Word: {0} Count:{1}", key.Key, key.Value)
and add the lines
RichTextBox2.AppendText(key.Key & " - " & key.Value & vbNewLine)

oh thank you so much actually I used the same sentence but instead of RichTextBox2.AppendText i used richtextbox2.text :D

You helped me alot thanks again

I still have a lot to learn

Have a good weekend XD

**Marked as solved + reputation