#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Building a Search Engine .. using Delphi 7


    Greeting Everybody
    well, I'm studying ITC in last level of BS..I need many many helps in my graduate project.
    it will be Search Engine , using data structures and text Files that's store in Hard disk.I will build and programmed by using Delphi language..
    I already started to learn it before 2 weeks ago , but I need strongly help to achieve my tasks .
    I wish that you are help me !

    Hint: I will keep this page for my Questions..

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    read the text of file


    The first attempt to read the text of file and display the text in Memo:

    Code:
    Var
    myFile:TextFile;
    text:string;
    
    procedure TForm1.ReadButtonClick(Sender: TObject);
    
    begin
    AssignFile(myFile, 'superComputer.txt');
    Reset(myFile);
    While not eof(myFile) Do
    Readln(myFile,text);
    Memo1.Lines.LoadFromFile('superComputer.txt');
    closeFile(myFile);
    end;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Question (1)


    How to extract each word from Text of File and store in Array without spaces?
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,641
    Rep Power
    4247
    Originally Posted by iTechnical
    The first attempt to read the text of file and display the text in Memo:

    Code:
    Var
    myFile:TextFile;
    text:string;
    
    procedure TForm1.ReadButtonClick(Sender: TObject);
    
    begin
    AssignFile(myFile, 'superComputer.txt');
    Reset(myFile);
    While not eof(myFile) Do
    Readln(myFile,text);
    Memo1.Lines.LoadFromFile('superComputer.txt');
    closeFile(myFile);
    end;
    Do you realize that most of that code you wrote does nothing useful at all? You could do the same thing with only one line of code
    Code:
    procedure TForm1.ReadButtonClick(Sender: TObject);
    begin
        Memo1.Lines.LoadFromFile('superComputer.txt');
    end;
    That's all there is to it.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,641
    Rep Power
    4247
    Originally Posted by iTechnical
    How to extract each word from Text of File and store in Array without spaces?
    Code:
    var 
        words : TStringList;
        MyString : String;
        idx: integer;
    begin
        MyString := "This is a test";
        words := TStringList.Create;
        // words.Delimiter := ' '; // This is the default. Uncomment and change to another character if you have a different delimiter.
        words.DelimitedText := MyString;
    
        // String should now be split by spaces
        for idx := 0 to words.count - 1 do
        begin
            ShowMessage(words[idx]);
        end;
    
        words.Free;
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by Scorpions4ever
    Do you realize that most of that code you wrote does nothing useful at all? You could do the same thing with only one line of code
    Code:
    procedure TForm1.ReadButtonClick(Sender: TObject);
    begin
        Memo1.Lines.LoadFromFile('superComputer.txt');
    end;
    That's all there is to it.
    Thank you Scorpions4ever

    But it was evaluation for me...
    How do I open the file and read the text inside it .

  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by Scorpions4ever
    Code:
    var 
        words : TStringList;
        MyString : String;
        idx: integer;
    begin
        MyString := "This is a test";
        words := TStringList.Create;
        // words.Delimiter := ' '; // This is the default. Uncomment and change to another character if you have a different delimiter.
        words.DelimitedText := MyString;
    
        // String should now be split by spaces
        for idx := 0 to words.count - 1 do
        begin
            ShowMessage(words[idx]);
        end;
    
        words.Free;
    end;

    it's working perfectly .
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    but my Supervisor asked me to defined an Array to store each word ! I'm still trying
    This is part of my attempt ...

    Code:
    const size=1000;
     var
     myFile:TextFile; 
    text:string; 
    I:integer; 
    MyArray:Array [1..size] of string;   
     begin 
    AssignFile(myFile, 'concepts.txt'); 
    Reset(myFile); 
    repeat
     Readln(MyFile,text); 
    // here should be write a condition to check a if the word between 2 spaces then take it and store in Array but I don't know HOW ?  :(
    
    
    // if the condition is True .. do this : 
    Begin 
    MyArray [I] := text; 
    I := I+1; 
    Until eof(MyFile); 
    End;
    What do you think ??
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    156
    Rep Power
    3
    There are flaws in your definition of word. If you only capture those between two spaces, then you will fail to capture word at the the start of the string, word at the end of the string, and words followed by punctuations.

    Anyway, it is better if you "walk" the source string. Use two integer variables to know the starting and end position to extract a word once one detected.

    Something like below (warning, not completed code, more like pseudocode).

    Code:
    var
      T: string;
      i, j: Integer;
    begin
      i := 1;
      for j := 1 to Length(SourceStr) do
      begin
        if SourceStr[j] is end of a word then
        begin
          T := Copy(ASourceStr, i, j-i);
          Add T to your array;
        end;
      end;
    end;
    For the array, you can use dynamic array. Declare it something like this.

    Code:
    var
      vArray: array of string;
    Note that using dynamic array you need to make sure it has sufficient size. You can alter its size with SetLength, similar like string. And dynamic arrays always start from 0.

IMN logo majestic logo threadwatch logo seochat tools logo