Autor Beitrag
HeinzKarl
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 19



BeitragVerfasst: Sa 25.12.10 19:26 
Hi,

ich habe ein kleines Problem. Ich möchte eine Zahl aus einer Textdatei laden, dannach überprüfen ob sie größer ist als Variabele A. Sollte sie größer sein, soll das Textdokument mit dieser Zahl überschrieben werden.

Problem:
In meiner Textdatei steht (z.B.):
Highscore 10

Einlesen tu ich das ganze so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
assignfile(highscore,'Score.txt');
reset(highscore);
readln(highscore,high);
Label1.Caption := high;
closefile(highscore);


Das Problem ist, high ist ein String, also einfach StrToInt gemacht:
ausblenden Delphi-Quelltext
1:
2:
if (Save = True) and (StrToInt(high) < Treffer) then
...


Aber high beinhaltet jetzt ja 'Highscore 10'.

Wie schaffe ich es NUR die ZAHL einzulesen ?

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Sa 25.12.2010 um 18:30
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Sa 25.12.10 19:57 
quick and dirty und nicht unbedingt immer verwendbar:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
For i:=0 to Length(myString)-1 do
 begin
  If(myString[i] in ['0'..'9')then
   result:= result + myString[i];
 end;

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
Stundenplan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 128
Erhaltene Danke: 32

Win 7
Delphi 7 Pers., C# (VS 2010 Express)
BeitragVerfasst: Sa 25.12.10 20:01 
Wenn das Muster immer gleich bleibt, d. h. "Highscore [Zahl]", dann kannst du auch mit Copy() arbeiten, damit kannst du einen Teilstring aus einem String extrahieren! :idea:
Syntax: S := Copy(Ein_String_aus_dem_was_ausgeschnitten_werden_soll, Startposition, Länge_des_Teilstrings);

Viele Grüße,
Stundenplan.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Sa 25.12.10 20:04 
oder...

ausblenden Delphi-Quelltext
1:
Delete(myString, 110);					


Also die ersten 10 Zeichen des Strings löschen...

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
HeinzKarl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 19



BeitragVerfasst: Sa 25.12.10 20:09 
Ja, der eingelesene Text heißt immer:
Highscore xxx

xxx = Eine Zahl beliebiger Länge

Ich probiere es mal aus, danke schonmal für die Hilfe.

//EDIT
Ich habe es mit Delete gemacht :) Funktioniert 1a.

Kann ich auch einen vorgegeben Text in einem String suchen und ausschneiden ?
z.B.
Aus A den String 'Hallo ' ausschneiden, damit nur noch 'Welt' übrig bleibt ?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 25.12.10 20:59 
Siehe dazu die Hilfe zu pos.