我需要有这样的字符串处理函数,
如:1,2,3,4,5,7,...
我希望有一个函数能实现按逗号分开,并把每个数字赋给数组的功能?

a[0]=1,a[2]=2,.......
请问有这样的函数吗

解决方案 »

  1.   

    // 将一由指定字串分隔的字符串分解到字串列表中
    // 参数: StrV-被分解的字符串  PrtSymbol-分隔符
    // 返回: 字符串列表(TStringList),注意在使用后要将其释放
    function PartitionString(StrV,PrtSymbol: string): TStringList;
    var
      iTemp: integer;
    begin
      result := TStringList.Create;
      iTemp := pos(PrtSymbol,StrV);
      while iTemp>0 do begin
        if iTemp>1 then result.Append(copy(StrV,1,iTemp-1));
        delete(StrV,1,iTemp+length(PrtSymbol)-1);
        iTemp := pos(PrtSymbol,StrV);
      end;
      if Strv<>'' then result.Append(StrV);
    end;