如题,这个字符串是6个字节,这个应该怎么做呢??

解决方案 »

  1.   

    var
      s1,s2:string;
    begin
      s1:='000000';
      s2:='81';
      if length(s2)<=6 then
        s1:=copy(s1,1,6-length(s2))+s2;
      result:=s1;
    end;
      

  2.   


    function GetStr(str1:String;str2:String):String;
    var
      iLen : Integer;
      sReturn : String ;
    begin
      iLen := Length(str2);
      if iLen <=6 then
        sReturn:=copy(str1,1,6 - iLen)+str2;
      Result := sReturn ;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      Str1,Str2,Str3:string;
       : String;
    begin
      str1:='000000';
      str2:='81';
      Str3 := GetStr(str1,str2) ;
      ShowMessage(str3);
    end;
      

  3.   

    用下面这个函数:function StringAdd(S1, S2: String):String;
    begin
      Result := Format('%.6d', [StrToInt(S1) + StrToInt(S2)]);
    end;
    调用的例子:procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(StringAdd('000000', '81'));
    end;
      

  4.   

    jadeluo  给的例子很不错!很实用!看一下就明白了!不愧为掌柜的等级啊!
      

  5.   

    to:jadeluo
     
    Format('%.6d', [StrToInt(S1) + StrToInt(S2)]);不错不错,我居然忘了那么好的东西。
      

  6.   

    Pascal年代就有的~对齐输出,呵呵
      

  7.   

    str := IntToStr(number);
    ShowMessage(StringOfChar('0',6-Length(str)) + str)