| | |
count concurrency words form a file
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 11
Reputation:
Solved Threads: 0
Hi again guys
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.
INPUT:
"That fox killed my rabbit, but my dog killed the fox"
OUTPUT:
but 1
dog 1
fox 2
killed 2
my
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.
OUTPUT:
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
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 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.INPUT:
"That fox killed my rabbit, but my dog killed the fox"
OUTPUT:
but 1
dog 1
fox 2
killed 2
my
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.
OUTPUT:
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
VBNET Syntax (Toggle Plain Text)
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 Try '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) Finally '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 Next Next 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
Last edited by doomfrawen; Aug 30th, 2009 at 1:33 am. Reason: Fixed something on the code
•
•
Join Date: Jun 2009
Posts: 258
Reputation:
Solved Threads: 50
Last edited by GeekByChoiCe; Aug 30th, 2009 at 1:58 am.
•
•
Join Date: Aug 2009
Posts: 11
Reputation:
Solved Threads: 0
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:
if anyone could help with this I'll really aprecciate it
Thanks in advance
VBNET Syntax (Toggle Plain Text)
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 Else dict.Add(word, 1) End If Next For Each key In dict 'this doesn't work to sort 'dict.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) Next End Sub
if anyone could help with this I'll really aprecciate it
Thanks in advance
![]() |
Similar Threads
- Determining the number of unique words in a .txt file (C++)
- determining frequency of words in text file (Python)
- Storing Words from Text File in Array (C++)
- Can you please help me write this word count program in another way (Python)
- I Need Help Writing A Word Count Program In My Python (Python)
Other Threads in the VB.NET Forum
- Previous Thread: How to specify a save location
- Next Thread: how i can delete value variable using vb.net
| Thread Tools | Search this Thread |
"crystal .net .net2005 2008 access add advanced application array assignment basic beginner box button buttons center click client code combo convert cpu data database datagrid datagridview designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall forms html image images isnumericfuntioncall listview login map math memory mobile module msaccess mssqlbackend mysql navigate net number opacity pan picturebox picturebox2 port print printpreview record regex reports" reuse right-to-left save savedialog search serial socket sorting sql sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter upload useraccounts usercontol usercontrol vb vb.net vb.nettoolboxvisualbasic2008sidebar vba vbnet vista visual visualbasic visualbasic.net visualstudio.net web winsock wpf wrapingcode xml





