Solved

How to read the text from Edit1 word-by-word?

Posted on 1998-12-16
14
267 Views
Last Modified: 2012-05-04
I have Edit1 (for example with text „No comment“), Button1 and Memo1. I would like to make this: When the user clicks on Button1, the program read first word and in Memo1 will show the german translate (Nein). Then the program read second word „comment“ and place the translate in Memo1 after the word „Nein“. How to make this?
0
Comment
Question by:rozanek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
  • +3
14 Comments
 

Expert Comment

by:lecossois
ID: 1351311
I would do it like this.

Make a function Translate(const S : String); that translates the word.

In the Button1 OnClick event you write the folling code :

const
  Separator = ' ';
var
  S     : String;
  Index : Integer;
begin
  S := Edit1.Text;
  Index := Pos(S,Separator);
  while Index > 0 do
    begin
      Memo1.Lines.Add(Translate(Copy(S,1,Index-1)));
      Delete(S,1,Index);
      Index := Pos(S,Separator);
    end;
  // Now there could be a last word
  If Trim(S) <> '' then
    Memo1.Lines.Add(Translate(S)));

0
 
LVL 1

Expert Comment

by:BlackDeath
ID: 1351312
what should this result in? a translator? which translates "no comment" to "nein kommentar"? that would be quite stupid, don't you agree?

and the parser lecossois wrote wouldn't work either.
look at: Index := Pos(S, Separator);
well.
in this case, it should be: Index := Pos(Separator, S);

(i don't believe the function would be able to find the passed parameter string (s) at any index within the separator (' '). it's more the other way round, isn't it?)

bye,

Black Death.
0
 

Expert Comment

by:lecossois
ID: 1351313
Ok, ok, I admit that I switched the Pos parameters.  But I don't have Delphi here at work, so I can't check what I write.  I definitely should be more careful when writing examples.

The fact that you don't consider this an interesting problem is irrelevant, because programmers are not allowed to question the specifications, are they (well, at least not in my company).

Greetings.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:BlackDeath
ID: 1351314
lecossois:
no offence meant.
i didn't say this won't be interesting.
i'm just of the opinion that it wouldn't make too much sense to translate phrases word-by-word.
a translator which works fairly usable would mean _lotsa_ mindwork, indeed quite an interesting task...

bye,

Black Death.
0
 

Expert Comment

by:lecossois
ID: 1351315
Backdeath, no offence taken.  I agree completely with your point.

Rozanek, is your problem part of a larger problem ?  Maybe there is a much better way of doing things.

Lecossois.

0
 

Expert Comment

by:lecossois
ID: 1351316
Backdeath, no offence taken.  I agree completely with your point.

Rozanek, is your problem part of a larger problem ?  Maybe there is a much better way of doing things.

Lecossois.

0
 

Author Comment

by:rozanek
ID: 1351317
This is no solution. I would like to make this: When the user write some sentence (for example "Good Morning, sir.") in Edit1 and press the Button1, in Memo1 will be this text appear: "Guten Morgen, Herr".
How to make this? I have no experience with Buffers or making functions.
0
 
LVL 2

Expert Comment

by:hrizal
ID: 1351318
just comment ... :)

if you no experience with buffers or making functions
try to cut and paste 'leccosois' answer, is easy way ...  :)
0
 
LVL 1

Accepted Solution

by:
skatan187 earned 100 total points
ID: 1351319
I used this for a simple search-engine thingy a while ago
(to search for all words givn:
search for "textone two three" for example,
it puts the words
one
two
three

In a lisbox, if you use a function to translate before putting the words in the listbox..)

memo1 = tempbox

function translate(str:string) : string;
begin
result:= ....;
end;

// make sure that there is a last ' ' in edit1.text
if edit1.text[length(edit1.text)] <> ' ' then edit1.text:=edit1.text + ' ';
x:=0;
// while not end of line do
 while x <> length(edit1.text) do begin
  inc(x);
  if upcasestr(edit1.text[x]) <> ' ' then
                 tmpstr:=tmpstr+edit1.text[x]
  else begin
   tempbox.items.add(translate(tmpstr));
   tmpstr:='';
  end;
   if x = length(edit1.text) then tempbox1.items.add(tmpstr);
 end;

0
 
LVL 1

Expert Comment

by:skatan187
ID: 1351320
Eum.. if you want to make a translation programm
Then If I was you,I would concentrate me more on the database
you will use =) .. start overtyping your dictionary now ... !


Sk
0
 
LVL 1

Expert Comment

by:skatan187
ID: 1351321
ow.. almost forgot:

for X:=1 to tembbox1.lines.count {- 1}  //not sure do
 edit2.text := edit2.text+' '+tempbox1.lines[x {-1}]
0
 
LVL 1

Expert Comment

by:slautin
ID: 1351322
It's parser problem.
In overall cases you must use lexical analizators (LEX for example).
I usially make my parsers.
After lexical analizators mabe you interesting by syntaxis
analizators :-).

Looking specification (writing for stdin and stdout):

%{
uses LexLib;
var words : array [1..100] of string;
    pos : word;
%}
%%
[a-zA-Z]+      begin
                words[pos]:=yytest;  
                inc(pos);
                end;
            |
\n            ;

%%

var i : Integer;

begin
  pos := 1;
  if yylex=0 then;
  for i := 1 to 100 do
       writeln(Words[i]);
end.

0
 

Author Comment

by:rozanek
ID: 1351323
For Skatan187: Thank you for solution. It's an easy way to make a translator in Delphi!
0
 
LVL 1

Expert Comment

by:skatan187
ID: 1351324
Hey.. thx =)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 204
Delphi application Soap connection 5 132
Delphi Yen format 3 62
scroll down TListBox component in Delphi 1 31
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question