AGB  ·  Datenschutz  ·  Impressum  







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

CSV Parser (wieder mal)

Ein Thema von taveuni · begonnen am 17. Jun 2009 · letzter Beitrag vom 18. Jun 2009
Antwort Antwort
Benutzerbild von Der.Kaktus
Der.Kaktus

Registriert seit: 22. Jan 2008
Ort: Erfurt
958 Beiträge
 
Delphi 7 Enterprise
 
#1

Re: CSV Parser (wieder mal)

  Alt 17. Jun 2009, 15:37
Hallo,
ich nutze seit Delphi4 dieses Tool..mir reicht es und ist einfach.
[c] iss nicht von mir aber Freeware!!!!

Delphi-Quellcode:
unit MyParser;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TMyParser = class(TComponent)
   private
      FieldSep: char;
      FLine: string;
      NumFields: byte;
      Index, Ct: array[0..255] of integer;
      function Getstr(n: byte): string;
         constructor Create( AParent : TComponent ); override;
    public
      property Sepchar: char read FieldSep write FieldSep;
      property count: byte read NumFields;
      property fields[n: byte]: string read Getstr; default;
      procedure Parse(const Line: string);
    end;

procedure Register;

implementation

constructor TMyParser.Create( AParent : TComponent );
begin
  inherited Create(aParent);
  FieldSep:=' ';
  FLine:='';
  NumFields:= 0;
end;

function TMyParser.Getstr(n: byte): string;
  begin
  result := '';
  if n > NumFields then
    exit;
  if n = 0 then
    result := FLine
  else if n > 0 then
   begin
    dec(n); {0-based arrays!}
    if Index[n] > 0 then
      result := copy(FLine, index[n], ct[n]);
   end;
  end;

procedure TMyParser.Parse(const line: string);
var
 i,p : byte;
 s: string;
 s2 : string;
begin
 Fline := Line;
 s:= line;
 NumFields := 0;
 i := pos(FieldSep, s);
 while i > 0 do
   begin
    s2 := copy (s,1,i -1);
    if NumFields = 0 then
     index[NumFields] := 1
    else
     index[NumFields] := pos(s2,fline);
    ct[NumFields] := length(s2);
    delete(s,1,i);
    i := pos(FieldSep, s);
    inc(NumFields);
   end;
end;




procedure Register;
begin
  RegisterComponents('Parser', [TMyParser]);
end;

end.
Anwendung..auch ganz einfach

Delphi-Quellcode:
  MyParser1.sepchar := ';';
  MyParser1.parse(s);
  for i := 1 to MyParser1.count do ListBox1.items.add(MyParser1.fields[i]);
hoffe, hilft Dir
Gruss Kaki

Repeat Until true=false;
  Mit Zitat antworten Zitat
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 02:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz