怎样取一个字符串的前几位和后几位。

解决方案 »

  1.   

    前n位:copy(s,1,n);
    后n位:copy(s,length(s)-n+1,n)
      

  2.   

    Var
    str:string;
    constr:string;
    begin
    str:='meng_xuan';
    constr=copy(str,1,3);  //=men
    showmessage(constr);
      

  3.   

    取后几位:function RightStr(const AText: string; ACount: Integer): string;
    取前几位:function LeftStr(const AText: string; ACount: Integer): string;
    任意取:  function Copy(S; Index, Count: Integer): string;
      

  4.   

    var
      str,s1,s2:string;
    begin
      str:='agdaedd';
      s1:=LeftStr(str,2);  //get 2 ,the result is 'ad';
      s2:=RightStr(str,3); //get 3 from back ,the result is 'edd';
      
    end;
      

  5.   

    随便取:  function Copy(S; Index, Count: Integer): string;
    后几位:function RightStr(const AText: string; ACount: Integer): string;
    前几位:function LeftStr(const AText: string; ACount: Integer): string;
      

  6.   

    来晚了,都说完了算了,来都来了(转载)^._____________.^随便取:  function Copy(S; Index, Count: Integer): string;
    后几位:function RightStr(const AText: string; ACount: Integer): string;
    前几位:function LeftStr(const AText: string; ACount: Integer): string;
      

  7.   

    MidStr,LeftStr,RightStr时别忘了Uses StrUtils;