Click here to Skip to main content
15,877,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Alright first my situation :

1) a text document which has content like :

uber|uber|ultra
taxi|taxi|taxi cab|cab|minicab|airport taxi|airport transfer
genitalia|genitalia|genitals
skincare|skincare|skin care|cosmetic|natual skin care|natural skin care
masses|masses|public|people|world|lots|plenty|wider public|herd|loads|amounts
you can do so|you can do so|that can be done
i wish the|i wish the|the manufacturers should
the reason is that|the reason is that|this is because
big issue|big issue|serious problem|major problem|big problem


this file has 64,000+ lines and all lines are like above. This file has english words and their synonyms.

2) an application with a richtextbox and a button. The user will write some text in the box and when he hits the button, the application will read the whole text and then do this :

* read the text file line by line
* find all the words in the box - the words are chosen by splitting the line from text file at "|". The first word is the word to find. For eg : uber, skincare, big issue etc.
* replace the word by the other part of split string

My code :

VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fil2 As New StreamReader("new2.txt")

        Dim i As Integer = 0
        Dim start2 As Integer = 0

        Do While fil2.Peek > -1
            Dim StringToCheck As String = fil2.ReadLine()
            Dim prev As String = ""

            If (StringToCheck.Split("|")(0).Split(" ").Count >= 2) Then
                Try
                    Dim z As Integer = RichTextBox1.Find(StringToCheck.Split("|")(0).Trim(), start2, RichTextBoxFinds.WholeWord)

                    If (z > 0) Then
                        'rtfArticle.SelectionColor = Color.Orange
                        RichTextBox1.Select(z, StringToCheck.Split("|")(0).Trim().Length)

                        Dim ss2 As String = ""
                        Dim ss3 As String = ""

                         If (RichTextBox1.SelectedText <> "") Then
                            
RichTextBox1.SelectedText = StringToCheck.Split("|")(1) & "|" & StringToCheck.Split("|")(2) & "|" & StringToCheck.Split("|")(3) & "|" & StringToCheck.Split("|")(4)
                                
                        End If

                        start2 = 0

                    End If

                Catch ex As Exception

                End Try
            End If
            

        Loop

        fil2.Close()


    End Sub


now the problem is that this takes hell lot of time. I tried with approx. 2500+ lines in richtextbox and it took 50 mins.

My thinking of solution : Iam thinking of running like 25 threads and passing 100 lines to each thread to the operation. But iam sure there should be another method or commercial component to do the same?

Any help plz.
Posted
Updated 12-Nov-11 20:26pm
v2
Comments
Mehdi Gholam 13-Nov-11 2:35am    
Have you tried working outside the RichtextEditor (string.Replace Split Find etc.)?
amit_upadhyay 13-Nov-11 3:06am    
nope. should i try that? Will it really make any difference ? Are gui components generally slow?
Mehdi Gholam 13-Nov-11 3:10am    
Yes they are very slow.
amit_upadhyay 13-Nov-11 3:20am    
ok thanks. i will try regex and string to see how it goes.

1 solution

You should try using regular expresions to find matches. Something like this

VB
Dim fileName As String = "D:\Documents\test.txt"
        Dim srText As New StreamReader(fileName)
        Dim text As String = srText.ReadToEnd()
        srText.Close()
        Dim regMatch As String = TextBox1.Text
        If Regex.IsMatch(text, regMatch) Then
            MessageBox.Show("Text found")
        End If


Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900