Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 28th, 2012, 05:06 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation 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

Reply With Quote
  #2  
Old December 28th, 2012, 05:15 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation 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;

Reply With Quote
  #3  
Old December 28th, 2012, 05:18 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
Question (1)

How to extract each word from Text of File and store in Array without spaces?

Reply With Quote
  #4  
Old December 28th, 2012, 05:36 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 32 m 40 sec
Reputation Power: 4080
Quote:
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

Reply With Quote
  #5  
Old December 28th, 2012, 05:48 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 9th Plane (9000 - 9499 posts)
 
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,390 Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 46th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 1 Day 22 h 32 m 40 sec
Reputation Power: 4080
Quote:
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;

Reply With Quote
  #6  
Old December 28th, 2012, 06:33 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
Quote:
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 .


Reply With Quote
  #7  
Old December 28th, 2012, 07:14 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation Power: 0
Quote:
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 .

Reply With Quote
  #8  
Old December 28th, 2012, 07:17 PM
iTechnical iTechnical is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 6 iTechnical User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 39 sec
Reputation 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 ??

Reply With Quote
  #9  
Old December 29th, 2012, 12:11 AM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 58 m 17 sec
Reputation Power: 2
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Building a Search Engine .. using Delphi 7

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap