060930-E016-0010-1
061009-aa-0009-2
061009-bbb-0009-3
061009-cccc-0009我想把以上字符串的最后两位不要,结果如下060930-E016-0010
061009-aa-0009
061009-bbb-0009
061009-cccc-0009大家帮忙看看,谢谢!

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
     tempstr : string;
    begin
      tempstr := copy(edit1.Text,0,edit1.GetTextLen-2);
      showmessage(tempstr);
    end;copy('字符串',开始位置,结束位置);
      

  2.   

    可是061009-cccc-0009 这个就不对了
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
        inttmp:integer;
        str:string;
        strtmp:string;
    begin
        str:='222-333-444';
        inttmp:=pos('-',str);  //取得第1个'-''的位置
        strtmp:=copy(str,inttmp+1,length(str));
        inttmp:=pos('-',strtmp);//取得第2个'-''的位置
        strtmp:=copy(strtmp,inttmp+1,length(strtmp));
        inttmp:=pos('-',strtmp);//取得第3个'-''的位置
        if inttmp=0 then
        begin
            //说明是最后一行的,然后自己写相关说明
        end
        else
        begin
            //说明不是最后一行的,然后自己写相关说明
        endend;
      

  4.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      i,j:Integer;
      TempStr,str:string;
    begin
      TempStr:='';
      j:=0;
      str:='061009-aa-0009';//需要处理的字串,你可以替换成你那里的任何形式
      while 0<3 do
      begin
        i:=0;
        i:=Find(str);
        if i>0 then
        begin
         j:=j+1;
         TempStr:=TempStr+Copy(str,1,i);
         if j=3 then
           Break;
         str:=Copy(str,i+1,Length(str)-i)
        end
        else
        begin
          TempStr:=TempStr+str;
          Break ;
        end;
      end;
      if j=3 then
        TempStr:=Copy(TempStr,1,Length(TempStr)-1);
      Edit1.Text :=TempStr;//显示最终结果
    end;function TForm1.Find(STR:string):Integer;
    begin
       Result :=pos('-',STR);
    end;