Recent

Author Topic: Sentence program  (Read 4122 times)

Querty

  • Newbie
  • Posts: 4
Sentence program
« on: February 08, 2016, 04:54:10 pm »
I need to do program where i read sentence from edit and separate words and write them in memo can you please help me with this?

balazsszekely

  • Guest
Re: Sentence program
« Reply #1 on: February 08, 2016, 05:15:48 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   SL: TStringList;
  4. begin
  5.   SL := TStringList.Create;
  6.   try
  7.     SL.Delimiter := ' ';
  8.     SL.DelimitedText := Edit1.Text;
  9.     Memo1.Lines.Text := SL.Text;
  10.   finally
  11.     SL.Free;
  12.   end;
  13. end;

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Sentence program
« Reply #2 on: February 08, 2016, 05:19:14 pm »
School assignment  O:-)

Bart

Querty

  • Newbie
  • Posts: 4
Re: Sentence program
« Reply #3 on: February 08, 2016, 05:23:10 pm »
Works fine thank you :)

balazsszekely

  • Guest
Re: Sentence program
« Reply #4 on: February 08, 2016, 05:23:21 pm »
@Bart
 :D In which country they teach Lazarus/Delphi?

PS: @majky. Try to put "," between the words, it will not work anymore,  so you need to adjust the code. If this really is a homework, then please make the necessary adjustments.   :)
« Last Edit: February 08, 2016, 05:26:53 pm by GetMem »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Sentence program
« Reply #5 on: February 08, 2016, 05:47:30 pm »
His name looks like Czech. Here in Indonesia many CS/IT campus also uses Delphi (instead of Lazarus unfortunately) to teach programming. The language still has strong foundation in education, only when money talks then it's beaten.

balazsszekely

  • Guest
Re: Sentence program
« Reply #6 on: February 08, 2016, 05:54:08 pm »
Quote
@Leledumbo
Here in Indonesia many CS/IT campus also uses Delphi
This is a good thing, Lazarus would be better, nevertheless delphi is still ok. I was under the impression that nowadays the only language they teach is: c#, php, python, ...

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Sentence program
« Reply #7 on: February 08, 2016, 10:19:07 pm »
If you want to teach structured programming, pascal is a good choice.

Bart

balazsszekely

  • Guest
Re: Sentence program
« Reply #8 on: February 08, 2016, 10:46:54 pm »
Quote
If you want to teach structured programming, pascal is a good choice.
That's true! Although I would like kids to learn more physics, astronomy and math, perhaps differential equations some day.  :)

sasa

  • Guest
Re: Sentence program
« Reply #9 on: February 09, 2016, 01:17:57 pm »
If this is school assignment or part of required task for a parser, this is not trivial assignment at all...

Proposal trivial solution cannon distinguish 'This is a sentence!' and 'This is a sentence !' or similar involving special characters... The 'sentence!' is not a word, as well as  '!'

That is the whole point in assignment. Not a single lexical parser is trivial.

Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. var
  3.   SL: TStringList;
  4. begin
  5.   SL := TStringList.Create;
  6.   try
  7.     SL.Delimiter := ' ';
  8.     SL.DelimitedText := Edit1.Text;
  9.     Memo1.Lines.Text := SL.Text;
  10.   finally
  11.     SL.Free;
  12.   end;
  13. end;

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: Sentence program
« Reply #10 on: February 09, 2016, 02:23:16 pm »
If it is an assignment, Tstringlist is not the best solution. It's nice (I used it myself to often), but cut the sentence in words and put them in an array.
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: Sentence program
« Reply #11 on: February 09, 2016, 04:40:34 pm »
School project or not, he's found his way here and that has to be a good thing surely ?  :)
This requirement is beyond the "Hello World" example but if the code works and can generate interest, Pascal gains another fan.

I do remember trying this sort of thing on my old Commodore Pet and 64 trying to emulate the original Adventure quests that were around back in the late 70s, early 80s.
Pick up torch, open door etc.
« Last Edit: February 09, 2016, 04:42:16 pm by Zath »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Sentence program
« Reply #12 on: February 09, 2016, 06:11:12 pm »
... Although I would like kids to learn more physics, astronomy and math, perhaps differential equations some day.  :)
High school:
Done physics
Done math
Done differential equations
No astronomy, alas (but did meteorology).

Bart

sasa

  • Guest
Re: Sentence program
« Reply #13 on: February 09, 2016, 07:28:33 pm »
Once again, majky, if you are high school student, try to do research yourself and basically rely on your school material, not on help from internet.

Lexical analyze and parsing is probably the chapter in your school book... You are the only one who know exactly what is the reason for assignment.

If you offer to your teacher proposed solution from this thread, you will probably receive zero or 1 point for the effort (from maximum 10)...

balazsszekely

  • Guest
Re: Sentence program
« Reply #14 on: February 09, 2016, 08:10:49 pm »
Quote
@Bart
High school:
Done physics
Done math
Done differential equations
No astronomy, alas (but did meteorology).
Yes, I know,  but you didn't graduated yesterday.  Nowadays the education has changed a lot, not necessarily in a good way...

@sasa, @mangakissa
We don't know if this is a school assignment or not, the OP was satisfied with the the solution, although I draw his attention about the limited capability of TStringList(see my second post). 

 

TinyPortal © 2005-2018