Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 23.11.06 18:58 
Mein FTP-Client muss irgendwie in mein PHP-Projekt Leerzeilen eingebaut haben. Auf jeden Fall sind einige Dateien total unübersichtlich geworden, diese Leerzeilen sollen wieder weg. Am liebsten hätte ich ein Delphi-Programm, dass ich drüberlaufen lassen könnte. Nur wie entferne Leerzeilen. Ich könnte alles in eine Stringlist einlesen und dann mit Delete arbeiten. Aber wie identifiziere ich eine Leerzeile?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Do 23.11.06 19:01 
du kannst das mit ASCII Code überprüfen

der ASCII code für ein Leerzeichen ist 32.

Wenn du jetzt nen String Buchstabe für Buchstabe überprüfst kannst du mit Ord(X) den ASCII Code rausfinden
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.11.06 19:04 
Moin!

user profile iconMarco D. hat folgendes geschrieben:
Ich könnte alles in eine Stringlist einlesen und dann mit Delete arbeiten. Aber wie identifiziere ich eine Leerzeile?

ausblenden Delphi-Quelltext
1:
2:
if (Trim(SL.Strings[i]) = ''then
  SL.Delete(i);

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 23.11.06 19:05 
user profile iconDragonclaw hat folgendes geschrieben:
du kannst das mit ASCII Code überprüfen

der ASCII code für ein Leerzeichen ist 32.

Wenn du jetzt nen String Buchstabe für Buchstabe überprüfst kannst du mit Ord(X) den ASCII Code rausfinden

Ich meine Leerzeilen! ;)
Kann ich nicht einfach die ganzen Stringlist durchgehen und wenn Stringlist1.Strings[i] = '' dann einfach diese Löschen?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.11.06 19:10 
:nixweiss:

_________________
There are 10 types of people - those who understand binary and those who don´t.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 23.11.06 19:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
var list: TStringlist; i: integer;
begin
  if (opendialog1.execute) then
  begin
    list := TStringlist.Create;
    list.LoadFromFile(opendialog1.FileName);
    for i := 0 to list.Count - 1 do
    begin
      showmessage(list.strings[i]);
      if (Trim(list.strings[i]) = ''then
         list.delete(i);
    end;

  end;

end;

Irgendwie liest er nur die 1. Zeile ein und dann folgen nur Leerzeilen. :gruebel:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 23.11.06 19:18 
Probier mal anstatt list.Strings[i] list[i].
Außerdem solltest du die Schleife rückwärts laufen lassen, da list.Count nur einmal am Anfang der Schleife abgefragt wird und wenn dann Zeilen gelöscht werden es eine Zugriffsverletzung gibt.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 23.11.06 19:25 
Perfekt es klappt :zustimm:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.Button1Click(Sender: TObject);
var list: TStringlist; i: integer;
begin
  if (opendialog1.execute) then
  begin
    list := TStringlist.Create;
    list.LoadFromFile(opendialog1.FileName);
    showmessage(inttostr(list.count));
    for i := list.count - 1 downto 0 do
    begin
      if (Trim(list[i]) = ''then
         list.delete(i);
    end;
    list.SaveToFile(extractfilepath(paramstr(0))+'dummy.php');
  end;

end;

Nur was ist der Unterschied zwischen list[i] und list.strings[i] ? :gruebel:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 23.11.06 19:38 
Eigentlich sollte es das gleiche sein, aber bei mir war es schon ein paar mal so, das list.strings[i] leer war und in list[i] die korrekten Werte standen. :shock:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Do 23.11.06 19:41 
user profile iconjakobwenzel hat folgendes geschrieben:
Eigentlich sollte es das gleiche sein, aber bei mir war es schon ein paar mal so, das list.strings[i] leer war und in list[i] die korrekten Werte standen. :shock:

:eyecrazy:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10184
Erhaltene Danke: 1259

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.11.06 20:01 
Moin!

user profile iconjakobwenzel hat folgendes geschrieben:
aber bei mir war es schon ein paar mal so, das list.strings[i] leer war und in list[i] die korrekten Werte standen.

Das glaube ich dir schlicht nicht. ;) Das ist exakt identisch und IMHO ist es besser das Array auch anzugeben, statt auf den Default zu setzen; kann man aber auf jeden Fall besser lesen.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 23.11.06 20:31 
Ich habs jetzt mal in nem seperaten Prog getestet, da gehts. :?
Aber in einem anderen Programm hab ich immer nur leere Strings gekriegt, bis ich das .strings gelöscht hab. :shock:
Ich kanns leider nich nochmal in dem anderen Prog testen, weil der entsprechende Code inzwischen wieder rausgeflogen is.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 23.11.06 22:04 
kleine frage: was passiert wenn in einer Zeile leerzeichen sind??

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Do 23.11.06 22:51 
Hallo,
user profile iconelundril hat folgendes geschrieben:
kleine frage: was passiert wenn in einer Zeile leerzeichen sind??

Gegenfrage, was macht die Funktion Trim? :roll:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.11.06 12:37 
Die Funktion Trim entfernt Leer- und Steuerzeichen aus einem String. ;)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Sa 25.11.06 11:07 
ok danke! hab nicht genau gewusst ob trim dazu da ist.

lg el

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.