我在Memo.Text中输入
 1.李吴青 2.李小燕 3.ZHANG/HUA MCDR3                                            
 4.  CZ3101 E   SA01MAR  CANPEK HK3   0800 1050          E                      
 5.CAN/T SZX/T 010-66671771/SZX LAISIDA AVIATION SERVICE LTD. IN CAN/HONG       
     XIANG NI ABCDEFG                                                           
 6.13713755669                                                                  
 7.TL/1900/25FEB/CAN695                                                         
 8.FC/A/CAN CZ PEK 850.00Y50 CNY850.00END                                       
 9.SSR FOID CZ HK1 NI350322850112567/P1                                         
10.SSR FOID CZ HK1 NI350322830202665/P2                                         
11.SSR FOID CZ HK1 NIE18806/P3                                                  
12.RMK CA/FPWFQ                                                                 
13.RMK AUTOMATIC FARE QUOTE                                                     
14.FN/A/FCNY850.00/SCNY850.00/C3.00/XCNY150.00/TCNY50.00CN/TCNY100.00YQ/        
    ACNY1000.00                                                                 
15.FP/CASH,CNY                                                                  
16.CAN695 
提交后如何得到下面这些数据
在StringGrid1.Cells[1,i]:=李吴青  李小燕 ZHANG/HUA
StringGrid1.Cells[2,i]:=350322850112567 350322830202665 E18806
Edit1.Text:=MCDR3  Edit2.Text:=CZ3101 Edit3.Text:=E Edit4.Text:=01MAR
Edit5.Text:=CANPEK Edit6.Text:=0800 Edit7.Text:=1050 Edit8.Text:=850.00
Edit10.Text:=50.00  Edit11.Text:=100.00  Edit12.Text:=1000.00
Memo.Text中的格式不变,只是人数会变如1个人就是:
 1.李吴青 MCEBH                                                                 
 2.  CZ3101 E   SA01MAR  CANPEK HK1   0800 1050          E                      
 3.CAN/T SZX/T 020-38771771/SZX LAISIDA AVIATION SERVICE LTD. IN CAN/HONG       
     XIANG NI ABCDEFG                                                           
 4.13713755669                                                                  
 5.TL/1900/25FEB/CAN695                                                         
 6.FC/A/CAN CZ PEK 850.00Y50 CNY850.00END                                       
 7.SSR FOID CZ HK1 NI350322850112567/P1                                         
 8.RMK AUTOMATIC FARE QUOTE                                                     
 9.RMK CA/G3MS5                                                                 
10.FN/A/FCNY850.00/SCNY850.00/C3.00/XCNY150.00/TCNY50.00CN/TCNY100.00YQ/        
    ACNY1000.00                                                                 
11.FP/CASH,CNY                                                                  
12.CAN695
两个人就是1.2.里面SSR FOID多了一个
这样子要怎么截取???在线等.请帮帮忙多谢...急用!!谢谢!!!

解决方案 »

  1.   

    看着有点没明白
    不过既然Memo中的格式是固定的,那就根据这个格式,写代码进行处理就行了.
      

  2.   

    主要是我对截取字符的这个代码还不理解的不深..序号又会变到我不知道怎么写了.用Memo.Lones也不能用的..只能从SSR这块入手我试了几天都没成功
      

  3.   

    提取某一行的记录用:
    str := memo1.lines.strings[i];确定某一行某个字符的位置用Pos;
    比如第二行中'4.'的位置;
    ipos = pos('4.',memo1.lines.strings[1]);
    取得第二行中'CZ3101'这个串;
    str1:=Copy(str; 3, 6: Integer);
    去空格
    str1:=Trim(Str1);如何确定CZ3101的起点呢,就是找到第一个空格的位置?
    在Str='4.     CZ3101   E       SA01MAR     CANPEK   HK3       0800   1050                     E '的情况下;
    pos(' ',str);如何取得"4.     CZ3101   E       SA01MAR     CANPEK   HK3       0800   1050                     E"第一个E呢?//取得第p个空格后的第一个字符的位置
    function TForm1.getPos(BText: String; p: integer): Integer;
    var
      Atext:String;
      i: Integer;
      S:String;//当前字符;
      Len: Integer;//整串的长度;
      isKong:Boolean; //遇到空格了;
      isUps: Boolean; //上一个字符是否为空格
      isS:Boolean;//遇到字符了;
      ip:Integer; //第N个空格;
      iend:Integer; //一个串的结尾;
    begin
      isKong := True; //默认情况下第一个字符为空格;
      isUps := false;  //默认上一个字符为空格;
      isS:=True;//默认情况下遇到字符了;
      AText := BText;
      Len := Length(AText);
      ip := 0;
      i:=0;
      While i < Len do
      Begin
          S := Copy(Atext,i,1);
          isKong := s=' ';
          // N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次;
          if (isKong) and (not isUps) then
          Begin
             Inc(ip);
          end;      //如果上一个字符为空格且当前字符不为空格;
          if not isKong and isUps  and (ip=p)then
          Begin
               Result := i;
               Exit;
          end ;      //标识状态;
          isUps := isKong;
          Inc(i);
      end;
    end;
    -------------------------------------------------------------------------------
    //取得第p个位置的字符串
    function TForm1.getPos(BText: String; p: integer): String;
    var
      Atext:String;
      i: Integer;
      S:String;//当前字符;
      Len: Integer;//整串的长度;
      isKong:Boolean; //遇到空格了;
      isUps: Boolean; //上一个字符是否为空格
      isS:Boolean;//遇到字符了;
      ip:Integer; //第N个空格;
      iBegin: Integer; //串的开始位置;
      iend:Integer; //一个串的结尾;
    begin
      isKong := True; //默认情况下第一个字符为空格;
      isUps := false;  //默认上一个字符为空格;
      isS:=True;//默认情况下遇到字符了;
      AText := BText;
      Len := Length(AText);
      ip := 0;
      i:=0;
      While i < Len do
      Begin
          S := Copy(Atext,i,1);
          isKong := s=' ';
          // N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次;
          if (isKong) and (not isUps) then
          Begin
              iEnd:= i;
             Inc(ip);
          end;      //如果上一个字符为空格且当前字符不为空格;
          if not isKong and isUps  and (ip=p)then
          Begin
               iBegin := i;
          end ;      if (isKong) and (not isUps) and (ip=p)then
          begin
             Result := Trim(copy(AText,iBegin,iend-iBegin));
             Exit;
          end;
          //标识状态;
          isUps := isKong;
          Inc(i);
      end;
    end;procedure TForm1.btn1Click(Sender: TObject);
    begin
     // ShowMessage(mmo1.Lines.Strings[0]);
     edt1.text := getPos(mmo1.Lines.Strings[0],2);
    end;end.
      

  4.   

    //取得第p个空格后的第一个字符的位置 
    function   TForm1.getPos(BText:   String;   p:   integer):   Integer; 
    var 
        Atext:String; 
        i:   Integer; 
        S:String;//当前字符; 
        Len:   Integer;//整串的长度; 
        isKong:Boolean;   //遇到空格了; 
        isUps:   Boolean;   //上一个字符是否为空格 
        isS:Boolean;//遇到字符了; 
        ip:Integer;   //第N个空格; 
        iend:Integer;   //一个串的结尾; 
    begin 
        isKong   :=   True;   //默认情况下第一个字符为空格; 
        isUps   :=   false;     //默认上一个字符为空格; 
        isS:=True;//默认情况下遇到字符了; 
        AText   :=   BText; 
        Len   :=   Length(AText); 
        ip   :=   0; 
        i:=0; 
        While   i   <   Len   do 
        Begin 
                S   :=   Copy(Atext,i,1); 
                isKong   :=   s='   '; 
                //   N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次; 
                if   (isKong)   and   (not   isUps)   then 
                Begin 
                      Inc(ip); 
                end;             //如果上一个字符为空格且当前字符不为空格; 
                if   not   isKong   and   isUps     and   (ip=p)then 
                Begin 
                          Result   :=   i; 
                          Exit; 
                end   ;             //标识状态; 
                isUps   :=   isKong; 
                Inc(i); 
        end; 
    end; 
    ------------------------------------------------------------------------------- 
    //取得第p个位置的字符串 
    function   TForm1.getPos(BText:   String;   p:   integer):   String; 
    var 
        Atext:String; 
        i:   Integer; 
        S:String;//当前字符; 
        Len:   Integer;//整串的长度; 
        isKong:Boolean;   //遇到空格了; 
        isUps:   Boolean;   //上一个字符是否为空格 
        isS:Boolean;//遇到字符了; 
        ip:Integer;   //第N个空格; 
        iBegin:   Integer;   //串的开始位置; 
        iend:Integer;   //一个串的结尾; 
    begin 
        isKong   :=   True;   //默认情况下第一个字符为空格; 
        isUps   :=   false;     //默认上一个字符为空格; 
        isS:=True;//默认情况下遇到字符了; 
        AText   :=   BText; 
        Len   :=   Length(AText); 
        ip   :=   0; 
        i:=0; 
        While   i   <   Len   do 
        Begin 
                S   :=   Copy(Atext,i,1); 
                isKong   :=   s='   '; 
                //   N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次; 
                if   (isKong)   and   (not   isUps)   then 
                Begin 
                        iEnd:=   i; 
                      Inc(ip); 
                end;             //如果上一个字符为空格且当前字符不为空格; 
                if   not   isKong   and   isUps     and   (ip=p)then 
                Begin 
                          iBegin   :=   i; 
                end   ;             if   (isKong)   and   (not   isUps)   and   (ip=p)then 
                begin 
                      Result   :=   Trim(copy(AText,iBegin,iend-iBegin)); 
                      Exit; 
                end; 
                //标识状态; 
                isUps   :=   isKong; 
                Inc(i); 
        end; 
    end; procedure   TForm1.btn1Click(Sender:   TObject); 
    begin 
      //   ShowMessage(mmo1.Lines.Strings[0]); 
      edt1.text   :=   getPos(mmo1.Lines.Strings[0],2); 
    end; end. 
      

  5.   

    完整代码如下:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        mmo1: TMemo;
        btn1: TButton;
        edt1: TEdit;
        procedure FormCreate(Sender: TObject);
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        function getPos(BText: string; p: integer): string;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    beginend;//取得第p个位置的字符串function TForm1.getPos(BText: string; p: integer): string;
    var
      Atext: string;
      i: Integer;
      S: string; //当前字符;
      Len: Integer; //整串的长度;
      isKong: Boolean; //遇到空格了;
      isUps: Boolean; //上一个字符是否为空格
      isS: Boolean; //遇到字符了;
      ip: Integer; //第N个空格;
      iBegin: Integer; //串的开始位置;
      iend: Integer; //一个串的结尾;
    begin
      isKong := True; //默认情况下第一个字符为空格;
      isUps := false; //默认上一个字符为空格;
      isS := True; //默认情况下遇到字符了;
      AText := BText;
      Len := Length(AText);
      ip := 0;
      i := 0;
      while i < Len do
      begin
        S := Copy(Atext, i, 1);
        isKong := s = ' ';
          // N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次,同时标识出串的结束位置;
        if (isKong) and (not isUps) then
        begin
          iEnd := i;
          Inc(ip);
        end;      //如果上一个字符为空格且当前字符不为空格,标识出串的开始位置;
        if not isKong and isUps and (ip = p) then
        begin
          iBegin := i;
        end;
          //返回第P个位置的字符串
        if (isKong) and (not isUps) and (ip = p) then
        begin
          Result := Trim(copy(AText, iBegin, iend - iBegin));
          Exit;
        end;
          //标识状态;
        isUps := isKong;
        Inc(i);
      end;
    end;procedure TForm1.btn1Click(Sender: TObject);
    begin
     // ShowMessage(mmo1.Lines.Strings[0]);
      edt1.text := getPos(mmo1.Lines.Strings[0], 2);
    end;end.
      

  6.   

    给你一个这样的例子,供你参考一下
    procedure TFrmReportPerson_FY.Button1Click(Sender: TObject);
    var
      strlist: TStringlist;
      destr: TStringlist;
      i: integer;
    begin
      strlist := TStringList.Create;
      destr := TStringList.Create;
      strlist.Add('1.李吴青 2.李小燕 3.ZHANG/HUAMCDR3 4.测试 5.其它测试');
      destr.Clear;
      destr.Delimiter := '.';
      destr.DelimitedText := strlist[0];
      for i:=0 to destr.Count-1 do
      begin
        if (i mod 2)=1 then
        memo1.Lines.Add(destr[i]);
      end;end;
      

  7.   

    这个测试通过.上面的有问题; unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        mmo1: TMemo;
        btn1: TButton;
        edt1: TEdit;  //返回值
        edt2: TEdit; //第几串
        edt3: TEdit; //第几行;
        procedure FormCreate(Sender: TObject);
        procedure btn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        function getPos(BText: string; p: integer): string;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    beginend;//取得第p个位置的字符串function TForm1.getPos(BText: string; p: integer): string;
    var
      Atext: string;
      i: Integer;
      S: string; //当前字符;
      Len: Integer; //整串的长度;
      isKong: Boolean; //遇到空格了;
      isUps: Boolean; //上一个字符是否为空格
      isS: Boolean; //遇到字符了;
      ip: Integer; //第N个空格;
      iBegin: Integer; //串的开始位置;
      iend: Integer; //一个串的结尾;
    begin
      //isKong := false; //默认情况下第一个字符为空格;
      isUps := True; //默认上一个字符为空格;
      isS := True; //默认情况下遇到字符了;
      AText := BText;
      Len := Length(AText);
      ip := 0;
      i := 1;
      iBegin := 1;
      while i < Len do
      begin
        S := Copy(Atext, i, 1);
        isKong := s = ' ';
          // N个连续的空格标识为一个空格;在上一个字符为不为空格且当前字符为字符为空格;,则加一次,同时标识出串的结束位置;
        if isKong then
        begin
          if not isUps then
          begin
            inc(ip);
            iEnd := i;
          end
        end else
        begin
          if isUps then
          begin
            iBegin := i;
          end
        end;
          //返回第P个位置的字符串
        if (isKong) and (not isUps) and (ip = p) then
        begin
          Result := Trim(copy(AText, iBegin, iend - iBegin));
          Exit;
        end;
          //标识状态;
        isUps := isKong;
        Inc(i);
      end;
    end;procedure TForm1.btn1Click(Sender: TObject);
    begin
      edt1.text := getPos(mmo1.Lines.Strings[StrToInt(edt3.text)], StrToInt(edt2.text));
    end;end.
      

  8.   

    我测试了怎么没反应啊..在Memo中输入:
      1.李吴青   2.李小燕   3.ZHANG/HUA   MCDR3                                                                                         
      4.     CZ3101   E       SA01MAR     CANPEK   HK3       0800   1050                     E                                             
      5.CAN/T   SZX/T   010-66671771/SZX   LAISIDA   AVIATION   SERVICE   LTD.   IN   CAN/HONG               
              XIANG   NI   ABCDEFG                                                                                                                       
      6.13713755669                                                                                                                                     
      7.TL/1900/25FEB/CAN695                                                                                                                   
      8.FC/A/CAN   CZ   PEK   850.00Y50   CNY850.00END                                                                               
      9.SSR   FOID   CZ   HK1   NI350322850112567/P1                                                                                   
    10.SSR   FOID   CZ   HK1   NI350322830202665/P2                                                                                   
    11.SSR   FOID   CZ   HK1   NIE18806/P3                                                                                                     
    12.RMK   CA/FPWFQ                                                                                                                                   
    13.RMK   AUTOMATIC   FARE   QUOTE                                                                                                           
    14.FN/A/FCNY850.00/SCNY850.00/C3.00/XCNY150.00/TCNY50.00CN/TCNY100.00YQ/                 
            ACNY1000.00                                                                                                                                   
    15.FP/CASH,CNY                                                                                                                                     
    16.CAN695 

      1.李吴青   MCEBH                                                                                                                                   
      2.     CZ3101   E       SA01MAR     CANPEK   HK1       0800   1050                     E                                             
      3.CAN/T   SZX/T   020-38771771/SZX   LAISIDA   AVIATION   SERVICE   LTD.   IN   CAN/HONG               
              XIANG   NI   ABCDEFG                                                                                                                       
      4.13713755669                                                                                                                                     
      5.TL/1900/25FEB/CAN695                                                                                                                   
      6.FC/A/CAN   CZ   PEK   850.00Y50   CNY850.00END                                                                               
      7.SSR   FOID   CZ   HK1   NI350322850112567/P1                                                                                   
      8.RMK   AUTOMATIC   FARE   QUOTE                                                                                                           
      9.RMK   CA/G3MS5                                                                                                                                   
    10.FN/A/FCNY850.00/SCNY850.00/C3.00/XCNY150.00/TCNY50.00CN/TCNY100.00YQ/                 
            ACNY1000.00                                                                                                                                   
    11.FP/CASH,CNY                                                                                                                                     
    12.CAN695 
    但是提交后得不到我想要的
      

  9.   

    最后一个例子我测试是通过了的.
    例子主要是取哪一行中的第几个字符串;
    比如:getPos(mmo1.Lines.Strings[0], 1)取得的是"1.李吴青"
    getPos(mmo1.Lines.Strings[0], 2)取得的是"2.李小燕"
    getPos(mmo1.Lines.Strings[0], 2)取得的是"3.ZHANG/HUA"
    getPos(mmo1.Lines.Strings[0], 2)取得的是"MCDR3 "
    getPos(mmo1.Lines.Strings[1], 1)取得的是"4."
    getPos(mmo1.Lines.Strings[1], 2)取得的是"CZ3101"
    getPos(mmo1.Lines.Strings[1], 3)取得的是"E" 你把他们都先取出来,再拼成你想要的结果就行了.
      

  10.   

    好象解析XML一样,头晕!!!