AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Text parsing - need method

Ein Thema von WojTec · begonnen am 16. Dez 2012 · letzter Beitrag vom 16. Dez 2012
Antwort Antwort
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#1

Text parsing - need method

  Alt 16. Dez 2012, 16:56
Delphi-Version: 2010
Sample:
Code:
ROWS 7
COLS 1
WIDTH 140
HEIGHT 30
TEXTHEIGHT 12
SPACING 1
R:247, G:224, B:23  HV:0.00, SV:0.00, VV:0.00  PANTONE Yellow C
R:247, G:217, B:23  HV:0.00, SV:0.00, VV:0.00  PANTONE Yellow 012 C
R:237, G:110, B:0  HV:0.00, SV:0.00, VV:0.00  PANTONE Orange 021 C
R:245, G:64, B:41  HV:0.00, SV:0.00, VV:0.00  PANTONE Warm Red C
R:237, G:46, B:56  HV:0.00, SV:0.00, VV:0.00  PANTONE Red 032 C
R:207, G:3, B:92  HV:0.00, SV:0.00, VV:0.00  PANTONE Rubine Red C
R:230, G:0, B:148  HV:0.00, SV:0.00, VV:0.00  PANTONE Rhodamine Red C
R:186, G:31, B:181  HV:0.00, SV:0.00, VV:0.00  PANTONE Purple C
R:102, G:0, B:161  HV:0.00, SV:0.00, VV:0.00  PANTONE Violet C
R:41, G:5, B:161  HV:0.00, SV:0.00, VV:0.00  PANTONE Blue 072 C
R:23, G:23, B:150  HV:0.00, SV:0.00, VV:0.00  PANTONE Reflex Blue C
I need to parse input in this format to get RGB and color name. Just question: do you know method how to get these data?
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#2

AW: Text parsing - need method

  Alt 16. Dez 2012, 17:18
Just split each line e.g. using a TStrings-object (have a look at the DelimitedText-property). If the resulting list contains more than 8 lines, it seems to be color-data, which you can process further.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#3

AW: Text parsing - need method

  Alt 16. Dez 2012, 17: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)
  Mit Zitat antworten Zitat
Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#4

AW: Text parsing - need method

  Alt 16. Dez 2012, 18:06
If you don't want to use the "delimitedText" try this way:
Delphi-Quellcode:
{pseudocode}
for i:=0 to lines.count-1 do begin
  if (pos('R:',line)>0) and
     (pos('G:',line)>0) and
     (pos('B:',line)>0) and
     (pos('PANTONE',line)>0) then
   GetDatafromLine(line)
  else
    donothing;
end;
Greetings
K-H
Programme gehorchen nicht Deinen Absichten sondern Deinen Anweisungen
R.E.D retired error detector
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#5

Re: Text parsing - need method

  Alt 16. Dez 2012, 18:52
Guys, 'PANTONE*' is color name RGB is color, HSV are not used (in all files I saw), after HSV is color name Sorry, I should write it early
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#6

AW: Text parsing - need method

  Alt 16. Dez 2012, 18:59
So what? Just ignore the values you do not need, and you are done.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#7

AW: Text parsing - need method

  Alt 16. Dez 2012, 19:02
I think a regular expression might be a simpler approach to get the relevant data.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
480 Beiträge
 
Delphi XE6 Professional
 
#8

Re: Text parsing - need method

  Alt 16. Dez 2012, 19:55
Hm, regex, but what lib for that?
  Mit Zitat antworten Zitat
Alt 16. Dez 2012, 22:25     Erstellt von Furtbichler
Dieser Beitrag wurde von MrSpock gelöscht. - Grund: Lieber gar nicht antworten als nur auf Google verweisen.
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:22 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz