简单而难的问题?因为中间有个分隔符,……
 谢谢你们……

解决方案 »

  1.   

    用StringReplace将串中的'-'转换成''
      

  2.   

    如果有空格或者其他的字符呢?
    介绍一个万无一失的方法://转换不成功则使用缺省值
    function XStrToIntDef(const S:string;Def:Integer=0);
    var
      tmp:string;
      i:Integer;
    begin
      for i:=1 to Length(S) do
        if S[i] in ['0'..'9'] then
          tmp:=tmp+S[i];
      Result:=StrToIntDef(tmp,Def);
    end;如果Delphi6及以下版本
    //转换不成功则使用缺省值
    function XStrToIntDef(const S:string;Def:Integer=0);
    var
      tmp:string;
      i:Integer;
    begin
      for i:=1 to Length(S) do
        if S[i] in ['0'..'9'] then
          tmp:=tmp+S[i];
      if tmp='' then
        Result:=Def
      else
      Result:=StrToInt(tmp);
    end;