Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
Delphi XE3 Enterprise
|
AW: Text parsing - need method
16. Dez 2012, 18:30
Delphi-Quellcode:
Type
TR=Record
R:byte;
G:Byte;
B:Byte;
HV:Double;
SV:Double;
VV:Double;
Panthone:String;
End;
Function GetInfos(Const s:String):TR;
var
sl:TStringList;
Function SaveStrToInt(const st:String):Integer;
begin
Result := StrToInt(TRIM(st));
end;
begin
sl:=TStringList.Create;
try
sl.Delimiter :=',';
sl.StrictDelimiter := true;
sl.DelimitedText :=StringReplace(
StringReplace(
StringReplace(
StringReplace(s,'HV:',',HV:',[])
,'PANTONE ',',PANTONE=',[])
,', ',',',[rfReplaceAll])
,':','=',[rfReplaceAll]);
Result.r := SaveStrToInt(sl.Values['R']);
Result.g := SaveStrToInt(sl.Values['G']);
Result.b := SaveStrToInt(sl.Values['B']);
Result.HV := StrToFloat(StringReplace(sl.Values['HV'],'.',DecimalSeparator,[]));
Result.SV := StrToFloat(StringReplace(sl.Values['SV'],'.',DecimalSeparator,[]));
Result.VV := StrToFloat(StringReplace(sl.Values['VV'],'.',DecimalSeparator,[]));
Result.Panthone := sl.Values['PANTONE'];
finally
sl.Free;
end;
end;
use as
Delphi-Quellcode:
var
r:TR;
I: Integer;
begin
for I := 0 to Yourlist.Count - 1 do
if pos('R:',Yourlist[i])=1 then
begin
r := getInfos(Yourlist[i]);
// work with r
end;
Thomas Wassermann H₂♂ Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂♂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
|
|
Zitat
|