对于不同长度的字符串,如何取出和去掉最后两个字符?
如:abcd-1 ---> abcd
    135-a  ---> 135

解决方案 »

  1.   

    copy (s,1,length(s) - 2);
      

  2.   

    可以查一个copy 和pos 两个函数
      

  3.   

    copy (s,1,length(s) - 2);
      

  4.   

    LeftStr(s,Length(s)-2);
    RightStr(s,2);
      

  5.   

    if length(s)>=2 then
      s:=copy (s,1,length(s) - 2);
      

  6.   

    正好弄了一个,uses 
      StrUtils
    var
      i,j:integer;
      s,x,y:string;
      str:array[0..10]of string;
    begin
      if rightstr(memo1.Text,2)='cb' then
        showmessage('结束');
      s:=leftstr(memo1.Text,length(memo1.Text)-2);
      for j:=0 to 10 do
        begin
          i:=pos('ee',s);
          if i>0 then
            begin
              x:=trim(copy(s,1,i-1));
              s:=trim(copy(s,i+2,length(s)));
              str[j]:=x;
            end
          else
            begin
              str[j]:=s;
              break;
            end;
        end;