Click here to Skip to main content
15,884,388 members

Running time take its too long for adding and finding string from txt C#

Berry Harahap asked:

Open original thread
Hello Brother, Sister, Buddy, Programmer, Master. :) :) :)

Based on running time for searching, this code take its too long.
Please give recommendation for making it efficient.

How to change or improve my code like this :

C#
static List<string> getDBList(string DBname)
{
     List<string> listWords = new List<string>();
     string[] files;

     try
     {
         files = Directory.GetFiles(@"dbase/", DBname); 
         foreach (string file in files)
             foreach (string line in File.ReadAllLines(file))//doubt
                listWords.Add(line.Trim().ToUpperInvariant());
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return new List<string> { };
     }

     return listWords;
}


Then...

C#
//MAIN PROGRAM
string allInput = rtbInput.Text;

List<string> splitString = new List<string>.Split(new char[] { ' ', '\t', etc...});
List<int> AllIndexes = new List<int>();
HashSet<string> nounList = new HashSet<string>(getDBList("nounList.txt"));//doubt

int startIndexes = 0;

foreach (string s in splitString)
{
    if (s.Trim() != "")
    {
       string word = s.Trim();

       if(!(nounList.Contains(word.ToUpperInvariant())))   //doubt, if not found, color it
       { 
               tbTest.Text += word + " ";

               //index to begin color the text
               AllIndexes = WordsIndex(word, startIndexes);

               foreach (int item in AllIndexes) //Coloring all appearance of the word.
               {
                   tbSeeIndex.Text += Convert.ToString(" " + item + " ");

                   rtbInput.Select(item, word.Length);

                   startIndexes = item + word.Length;

                   rtbInput.SelectionColor = Color.Red;
              }

              tbL.Text += Convert.ToString(" " + startIndexes + " ");
        }
    }
}            


in nounList (90963 word), content like this example :
book
chari
pencil
table
etc...

Please help me.....

Thanks a lot. :) :) :) Cheers
Tags: C#, Visual Studio

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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