如何将单词转换成句子?

时间:2016-02-21 08:59:55

标签: delphi

我必须要求用户输入单词(一次一个),直到输入“xxx”。然后我必须用每个单词之间有一个空格的单词构建一个句子。输入终止字符串(“xxx”)后,必须立即显示该句子。

我的代码只显示终止代码“xxx”。

注意:我们还没有开始使用Arrays。

这是我到目前为止尝试的代码:

unit BuildSentence_U;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
  btnResult: TButton;
redOut: TRichEdit;
procedure btnResultClick(Sender: TObject);
private
  { Private declarations }
public
  { Public declarations }
end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btnResultClick(Sender: TObject);
Var wrd : string;
begin

wrd := inputbox('Word input', ' Enter any word to build a sentence     (press "xxx" to stop)','');
redOut.Clear;

while (wrd <> 'xxx') do
 begin
  wrd := wrd + ' ';
  wrd := inputbox('Word input', ' Enter any word to build a sentence (press"xxx" to stop)','');
 end;
redOut.Lines.Add(wrd);
end;

end.

1 个答案:

答案 0 :(得分:1)

使用另一个字符串来收集单词:

alter trigger tr2 on bb
instead of insert
as
begin
    begin try
        begin transaction
            if exists(select * from inserted where date1  > getdate())
                    begin
                        raiserror('date greater then today''s date',16,1)
                    end

                else
                    begin
                        insert into bb
                        select * from inserted
                        if @@trancount > 0
                        commit transaction
                    end
    end try

    begin catch
        declare @msg varchar(100) = error_message()
            if @@trancount > 0
                begin
                    raiserror(@msg,16,1)
                    rollback transaction
                end         
    end catch
end