比如产品批号为:Sr350,下一个想为上一个加1,即sr351该怎么办呢,还有sr_350这种类型,这种格式应该怎么转化,但是未位都是数字.strtoint貌似不行,

解决方案 »

  1.   


    Inc(AddNum);
    PiHao1Label:= Format('Sr_%d',[AddNum]);
    PiHao2Label:= Format('Sr%d',[AddNum]);
      

  2.   

    只要字符串格式、数字位数明确,如Sr350、sr_350,取字串作转换就可以了
    如:由Sr350得到Sr351
    'Sr' + IntToStr(StrToIntDef(RightStr('Sr350', 3), 0) + 1)
      

  3.   

    inttostr(inc(Cut(s)));
    cut 自己写
    呵呵
    纯属灌水
      

  4.   

    你一开始就应该把字符串和数字分开,
    等到要写的时候再str=前缀+inttostr(数字);
      

  5.   

    'Sr' + IntToStr(copy('批号',Length(批号)-2+1,length(批号)-2));
      

  6.   

    楼上均未考虑填充的问题。。
    CR000001  加1 后应该是cr00002而不是cr2,
      

  7.   

    function AddByString(const ASTR: string; const ANUM: Integer = 1): string;
      function FillSpace(const ASTR: string; const ALEN: Integer): string;
      begin
        Result := ASTR;
        while (Length(Result) < ALEN) do
        begin
          Result := '0' + Result;
        end;
      end;
    var
      i, iLen: Integer;
      s: string;
    begin
      iLen := Length(ASTR);
      for i := iLen downto 1 do
      begin
        if not (ASTR[i] in ['0'..'9']) then
          Break;
      end;
      if i <> iLen then
      begin
        Result := LeftStr(ASTR, i) + FillSpace(IntToStr(StrToInt(RightStr(ASTR, iLen - i)) + ANUM), iLen - i);
      end;
    end;