Thema: Delphi Liste parsen

Einzelnen Beitrag anzeigen

Nuclear-Ping
(Gast)

n/a Beiträge
 
#2

Re: Liste parsen

  Alt 20. Dez 2005, 14:39
Delphi-Quellcode:
type
  TExplodeArray = Array of String;

{ ************************************************************ }
function Explode (const cSeparator, vString: WideString): TExplodeArray;
{ ************************************************************ }
var
  i: Integer;
  S: String;
begin
  S := vString;
  SetLength(Result, 0);
  i := 0;
  while Pos(cSeparator, S) > 0 do begin
    SetLength(Result, Length(Result) +1);
    Result[i] := Copy(S, 1, Pos(cSeparator, S) -1);
    Inc(i);
    S := Copy(S, Pos(cSeparator, S) + Length(cSeparator), Length(S));
  end;
  SetLength(Result, Length(Result) +1);
  Result[i] := Copy(S, 1, Length(S));
end;

{ ************************************************************ }
function Implode (const cSeparator: WideString; const cArray: TExplodeArray): String;
{ ************************************************************ }
var
  i: Integer;
begin
  Result := '';
  for i := 0 to Length(cArray) -1 do begin
    Result := Result + cSeparator + cArray[i];
  end;
  System.Delete(Result, 1, Length(cSeparator));
end;

...

Str := 'Wort1|Wort2|Wort3|...';

StrItems := Explode ('|', Str);

if (StrItems[0] = 'Wort1') then
  StrItems[3] := 'Neues Wort';

Str := Implode ('|', StrItems);
Suchst du vielleicht das?
  Mit Zitat antworten Zitat