首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

请教字符分割的有关问题

2013-03-14 
请问字符分割的问题有这样一个字符 temp:a 2 or b 3and c 4or d 5字符or 跟 a

请问字符分割的问题
有这样一个字符 
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
谢谢!
[解决办法]

unit Unit13;

interface

uses
  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.

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

热点排行