property CommaText: string;
请问用这个方法怎么处理“1,2,3,4”这样的字符串,请给出相应的例子参考一下!谢谢了!

解决方案 »

  1.   

    给你一函数:
    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;调用:
    var
      Str:TStrings;
      TStr:String;
    begin
      TStr:='1,2,3,4';
      Str:=PartitionString(TStr,',');
    end;
      

  2.   

    TStringList.Text:= StringReplace(AString, #13, '', [rfReplaceAll]);
      

  3.   

    procedure TStrings.SetCommaText(const Value: string);
    begin
      Delimiter := ',';
      QuoteChar := '"';
      SetDelimitedText(Value);
    end;procedure TStrings.SetDelimitedText(const Value: string);
    var
      P, P1: PChar;
      S: string;
    begin
      BeginUpdate;
      try
        Clear;
        P := PChar(Value);
        while P^ in [#1..' '] do
        {$IFDEF MSWINDOWS}
          P := CharNext(P);
        {$ELSE}
          Inc(P);
        {$ENDIF}
        while P^ <> #0 do
        begin
          if P^ = QuoteChar then
            S := AnsiExtractQuotedStr(P, QuoteChar)
          else
          begin
            P1 := P;
            while (P^ > ' ') and (P^ <> Delimiter) do
            {$IFDEF MSWINDOWS}
              P := CharNext(P);
            {$ELSE}
              Inc(P);
            {$ENDIF}
            SetString(S, P1, P - P1);
          end;
          Add(S);
          while P^ in [#1..' '] do
          {$IFDEF MSWINDOWS}
            P := CharNext(P);
          {$ELSE}
            Inc(P);
          {$ENDIF}
          if P^ = Delimiter then
          begin
            P1 := P;
            {$IFDEF MSWINDOWS}
            if CharNext(P1)^ = #0 then
            {$ELSE}
            Inc(P1);
            if P1^ = #0 then
            {$ENDIF}
              Add('');
            repeat
              {$IFDEF MSWINDOWS}
              P := CharNext(P);
              {$ELSE}
              Inc(P);
              {$ENDIF}
            until not (P^ in [#1..' ']);
          end;
        end;
      finally
        EndUpdate;
      end;
    end;这是VCL源码
    类本身提供了这个对象方法
      

  4.   

    property CommaText: string read GetCommaText write SetCommaText;

    是公布了属性
    你自己也可以按照VCL的处理方式写一个