有这样一个字符 
temp:='a = ''2'' or b = ''3''  and c = ''4''  or d = ''5'''
字符or 跟 and 是之间位置是随意调换
请问现在如何把字符temp分割成
a='2' or
b='3' and
c='4' or
d='5
谢谢!

解决方案 »

  1.   

    提示下;自己创建个split类似函数;例如 function getWords(Sword:string;sp:string;strI,endI:integer):string;
      

  2.   

    unit Unit13;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm13 = class(TForm)
        edt1: TEdit;
        btn1: TButton;
        mmo1: TMemo;
        procedure btn1Click(Sender: TObject);
      private
        procedure Split_And(Str : string);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form13: TForm13;implementation
    const
      S_OR = ' or ';
      S_AND = ' and ';
    {$R *.dfm}
    procedure TForm13.Split_And(Str : string);
      procedure Split_Or(Str : string);
      var
        index : integer;
      begin
        index := Pos(S_OR, Str);
        while index > 0 do
        begin
          mmo1.Lines.Add(Copy(Str, 1, index + Length(S_OR) - 1));
          Str := Copy(Str, index + Length(S_OR), Length(Str));
          index := Pos(S_OR, Str);
        end;
        mmo1.Lines.Add(Str);
      end;
    var
      index : integer;
    begin
      index := Pos(S_AND, Str);
      while index > 0 do
      begin
        Split_Or(Copy(Str, 1, index + Length(S_AND) - 1));
        Str := Copy(Str, index + Length(S_AND), Length(Str));
        index := Pos(S_AND, Str);
      end;
      Split_Or(Str);
    end;procedure TForm13.btn1Click(Sender: TObject);
    begin
      mmo1.Clear;
      Split_And(edt1.Text);
    end;end.
      

  3.   

    最简单的办法.替换 or 成 or+#13  替换 and 成 and+#13 然后用 TStringList 装载一下就OK了.