![]() |
Problem mit String in Schleife
Gutn Aabend :-D ,
Hab ein, für mich, sehr nervenaufreibendes Problem mit einer Schleife. Vielleicht kann mir ja jemand helfen. Also ich hab einen String mit HTML-Code, der is circa 70 Kb groß und heisst htmlbuffer. Aus diesem suche ich Jahreszahlen beginnend mit 1 und dann sollen natürlich 3 weitere Zahlen folgen. Hier ein Codeauszug:
Delphi-Quellcode:
Der Code funktioniert, aber nur wenn ich htmlbuffer um circa 10000 Bytes kürze, was ja total lächerlich ist, ich will ja den ganzen Quelltext durchsuchen lassen.
While i < length(htmlbuffer) do
begin keindatum := 0; index := PosEx('1', htmlbuffer, i); if index > 0 then begin datum := '1 '; For a:= 1 to 3 do begin if ((htmlbuffer[index + a]) = '1') or ((htmlbuffer[index + a]) = '2') or ((htmlbuffer[index + a]) = '3') or ((htmlbuffer[index + a]) = '4') or ((htmlbuffer[index + a]) = '5') or ((htmlbuffer[index + a]) = '6') or ((htmlbuffer[index + a]) = '7') or ((htmlbuffer[index + a]) = '8') or((htmlbuffer[index + a]) = '9') then datum[1 + a] := htmlbuffer[index +a] else keindatum := 1; end; if keindatum = 0 then liste := liste + ' ' + datum; end; i := index + 1; end; memo1.text := liste; end; Versuche ich das dann reagiert das Programm nicht mehr! Aber htmlbuffer ist vollständig, hab es mir in einem Memo angeschaut. Kann es sein, dass es einen Überlauf gibt? Hab keine Ahnung! Was kann ich da bloss machen :? ? |
Re: Problem mit String in Schleife
Hallo,
ich hab' Deinen Quelltext mal etwas vereinfacht und in Form gebracht (das kann ja keiner lesen :wink: ). Ich vermute, Du hast eine Endlosschleife, da Du, wenn zwar eine Eins, aber kein Datum keine Eins gefunden wird, immer wieder die gleiche Stelle untersuchst. Ein Break wirkt da Wunder. Außerdem ist jetzt eine Abfrage drin, dass Du nicht über das Stringende hinaus liest. Versuch' mal, ob das so funktioniert:
Delphi-Quellcode:
Gruß
var
L: Integer; a, i: Integer; IsDatum: Boolean; ... L := Length(htmlbuffer); while i < L do begin IsDatum := True; Index := PosEx('1', htmlbuffer, i); if (Index > 0) and (Index <= L - 3) then begin Datum := '1 '; for a := 1 to 3 do if htmlbuffer[Index + a] in ['0'..'9'] then Datum[a + 1] := htmlbuffer[Index + a] else IsDatum := False; if IsDatum then Liste := Liste + Datum; i := Index + 1; end else Break; end; memo1.text := Liste; xaromz |
Re: Problem mit String in Schleife
Wow jetzt gehts :shock:
Programmier erst seit ca. 2 Wochen. Sieht man wohl auch an meinen Quelltext, wah? DANKE Dir 1000 mal. Bin schon fast dran verzweifelt --> müsste mir doch wohl mal ein Delphi-Büchlein besorgen. |
DP-Maintenance
Dieses Thema wurde von "JasonDX" von "Neuen Beitrag zur Code-Library hinzufügen" nach "Sonstige Fragen zu Delphi" verschoben.
Nix CodeLib, bitte etwas auf die Sparte achten, Danke ;) |
Re: Problem mit String in Schleife
Der Code
Delphi-Quellcode:
Ist noch ein wenig schneller ;)
while i < L do
begin IsDatum := True; Index := PosEx('1', htmlbuffer, i); if (Index > 0) and (Index <= L - 3) then begin if (htmlbuffer[Index + 1] in ['0'..'9']) and (htmlbuffer[Index + 2] in ['0'..'9']) and (htmlbuffer[Index + 3] in ['0'..'9']) then Datum := Copy(htmlbuffer, Index, 4); else IsDatum := False; if IsDatum then Liste := Liste + Datum; i := Index + 1; end else Break; end; memo1.text := Liste; |
Re: Problem mit String in Schleife
1A
:thumb: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:17 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