求一个字符串的函数?我假如有一串数字,如:1,2,3,4,5,7,33,22 ...我想把几个连续的数据作为一个字符串相加是这个样子,'1-5';假如我把一个不连续的数字相加,就这样,  7,9,33我要把这两种情况合在一起形成一个函数,请问如何写?这种情况(1-5,7,9,)这种字符串怎样形成!

解决方案 »

  1.   

    怎么没人回答啊!可不可以帮我解决一下这个函数啊!我单击一个按钮怎样执行一个EXE文件,比如我要执行 "计算机管理" 这个EXE文件,我该怎样取得系统的路径和执行这个EXE文件!谢谢了!
      

  2.   

    我写了一个大概的算法,但还不够精确,你自己再改一下procedure TForm1.Button1Click(Sender: TObject);
    var
      strTest,RowStr,Result: String;
      strList: TStringList;
      i,temp: Integer;
    begin
      strList := TStringList.Create;
      strTest := '1,2,3,4,5,7,9,33,907,8888,8889,8890';  //得到第一个数字
      temp := StrToInt(LeftStr(strTest,Pos(',',strTest)-1));  strList.Text := WrapText(strTest,#13,[','],1);  for i := 0 to strList.Count - 1 do
      begin
        //得到下一个数字
        if RightStr(strList.Strings[i],1) = ',' then
          RowStr := LeftStr(strList.Strings[i],Length(strList.Strings[i])-1)
        else
        begin
          RowStr := strList.Strings[i];
        end;    //比较
        if (StrToInt(RowStr) > temp) and (StrToInt(RowStr) - temp = 1) then
        begin
          Delete(Result,Length(Result),1);
          Result := Result + '-';
          temp := StrToInt(RowStr);
        end
        else
        begin
          temp := StrToInt(RowStr);
          Result := Result + RowStr + ',';
        end;
      end;//end for
      strList.Free;
      ShowMessage(Result+IntToStr(temp));
    end;我的Email:[email protected]