Autor Beitrag
walvaterwotan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: Sa 08.10.05 16:00 
Hi Leuts,

Ich habe einen String, aus dem Quellcode einer Internetseite ausgelesen, welcher eine Zahl ist. Nun kann diese Zahl aber zwei, oder drei Stellen haben. Das Problem dabei ist, dass wenn der String nur aus zwei Zahlen besteht, ist das 3. Zeichen keine Zahl.
Somit kann ich den String nicht einfach generell in eine Zahl umwandeln, da ein Konflikt enstehen würde, da es ja kein Integerwert ist, wenn ich den Stringwert in einen Integerwert umwandle.

Umm es zu veranschaulchen:
1. String auslesen (aus 3 Stellen bestehend)
2. String kann "Zahl Zahl Zahl" sein, oder "Zahl Zahl Zeichen"

Ich müsste also irgendwie überprüfen, ob ich den String in einen Integerwert umwandeln dürfte, wenn nicht, dann schneide die letzte Stelle ab.
ALso sowas in der Art wie: "If String can be Integer Then ..."

Wenn es sowas in der Art nicht gibt, dann muss ich den String wohl jedesmal auf die 3. Stelle überprüfen und wenn diese Stelle ein bestimmtes Zeichen ist, dann ist die Zahl zweistellig und muss die letzte STelle abschneiden.

Hoffe, ihr habt mein Problem verstanden, denn es ist irgendwie blöd erklärt :/

Danke schonmal .... Patrick
GSE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 740

Win 2k, Win XP Pro
D5 Prof, D6 Ent, D2k5 PE
BeitragVerfasst: Sa 08.10.05 16:23 
Hi,
schau dir mal in der Hilfe die Val Funktion an.
müsste dann ungefähr so aussehen(nicht getestet!):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var
e, i: integer;
s: string;
{...}
begin
{...}
Val(s, i, e);
if e <> 0 then
begin
 Delete(s, 3, 1);
 Val(s, i, e);
end;
// In i ist jetzt deine Zahl


mfg
GSE

_________________
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs
and the universe trying to produce bigger and better idiots. So far, the universe is winning. (Richard Cook)
SMO
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 120
Erhaltene Danke: 18


D2005 Personal
BeitragVerfasst: Sa 08.10.05 16:25 
Noch eine Möglichkeit: die Funktion TryStrToInt (siehe Delphi-Hilfe)
walvaterwotan Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 23



BeitragVerfasst: Sa 08.10.05 16:37 
Danke ihr Beiden! Funtzt super!

Hab die 2. Variante gewählt, da die doch ein wenig leichter ist, wobei ich mir auch die 1. anschauen werde, einfach um n bissel was dazuzulernen.

Bis denne,
Patrick
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 08.10.05 16:38 
Als Alternative kannst Du auch folgenden Source nutzen:

ausblenden Delphi-Quelltext
1:
IsValue := StrToIntDef(S, 0) = StrToIntDef(S, -1);					


Die Funktion TryStrToInt gibt es erst ab D6 oder D7 (bin mir nicht sicher).

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Sa 08.10.05 16:48 
user profile iconBenBE hat folgendes geschrieben:
Die Funktion TryStrToInt gibt es erst ab D6 oder D7 (bin mir nicht sicher).

In Delphi 3 geht sie nicht aber in D2005. Nur um dich zu informieren^^
Benutzername
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 210

Win XP Pro
Delphi 7 PE, D2005 Prof. SSL
BeitragVerfasst: Sa 08.10.05 18:10 
user profile iconDarkLord05 hat folgendes geschrieben:
user profile iconBenBE hat folgendes geschrieben:
Die Funktion TryStrToInt gibt es erst ab D6 oder D7 (bin mir nicht sicher).

In Delphi 3 geht sie nicht aber in D2005. Nur um dich zu informieren^^


Nur so, wenn du in diesen Satz kein Komma setzt, isser zweideutig ;)
Entweder
In Delphi 3 geht sie, nicht aber in D2005.
oder
In Delphi 3 geht sie nicht, aber in D2005.

;)
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Sa 08.10.05 18:19 
^^ Stimmt. Danke für den Hinweis.

Ich meine natürlich:
In Delphi 3 geht sie nicht, aber in D2005.
(das nicht ist so auf Delphi 3 bezogen)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 08.10.05 22:25 
Ein Glück, dass hier alle lesen können ;-)

Ich hab geschrieben, das es FRÜHSTENS ab D6 funktioneirt --> Delphi 3 geht absolut nicht über diese Funktion zum gewünschten Ergebnis zu bewegen ;-) Und da D9 der Nachfolger von D7 ist, gibt es keinerlei Probleme zu erwarten.

Ich hab mal kurz in D6 nachgeguckt: TryStrToInt existiert bereits in D6.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
DarkLord05
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 449

WinXP Pro SP2
Opera; Delphi 3 Pro; Delphi 2005, Turbo Delphi, dev-c++, Eclipse, MS Visual Studio .NET 2003, MS Visual C++
BeitragVerfasst: Sa 08.10.05 23:38 
Ich habs ja gesehen und wollte das nur nochmal bestätigen was du gesagt hast, da du dir ja nicht sicher warst.