Registriert seit: 11. Apr 2003
88 Beiträge
Delphi 7 Professional
|
Re: String richtig zerlegen
5. Sep 2008, 13:52
Und warum nicht einfach so. bzw so ähnlich (übergabe, funktion usw....)
Gruß
Stefan
Delphi-Quellcode:
procedure parse();
var parse1, Parse2, parse3 : string;
loop: integer;
theList : TStrings;
varLine : string;
defLine : string;
begin
thestr2Parse := '{"class":"Shaman","spec":"Enhancement","role":"DPS","talents":"0\/45\/16","gearraw":"226.63","gearbuffed":"250.99","warncount":1,"rawpos":527,"buffpos":600}';
Parse1 := copy(theStr2Parse, 2, length(theStr2Parse)-2);
parse2 := AnsiReplaceStr(Parse1,':','=');
parse3 := AnsiReplaceStr(Parse2,'"','');
theList := TStringList.Create;
theList.CommaText := parse3;
memo1.Clear;
varLine := 'var ';
for loop := 0 to theList.Count-1 do
begin
varLine := varLine + theList.Names[loop];
if loop = theList.Count-1 then varLine := varLine+';'
else varLine := varLine+',';
end;
memo1.Lines.Append(varLine);
memo1.Lines.Append('begin');
for loop := 0 to theList.Count-1 do
begin
defLine := #9+theList.Names[loop]+' := '+#39+theList.ValueFromIndex[loop]+#39+#59;
memo1.Lines.Append(defLine);
end;
memo1.Lines.Append('end;');
theList.Free;
end;
|
|
Zitat
|