Autor Beitrag
Morpheus1572
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157

Win XP
Delphi 7
BeitragVerfasst: Sa 13.09.08 21:59 
moin,

ich steh grad mächtig im wald und meine brotkrumen sind von den bösen waldbewohnern aufgefressen worden.

ich habe einen string in dem ein datum steht (01012008).

wie mache ich daraus ein datum (01.01.2008) oder einen String (01.01.2008) beides ist mir recht, ich weiß nur grad nicht wo ich ansetzen soll.

Hat jemand nen brot für mich?

Thx Morph.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 13.09.08 22:17 
Mit Copy() zerlegen

_________________
Markus Kinzler.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 13.09.08 22:41 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var s1, s2: shortstring
cae Datum: tdate;
const Datumsstring = '12032006'///Datums-String
begin
s1 := datumsstring;
s2 := s1[1]+s1[2]+'.'+s1[3]+s1[4]+'.'+s1[5]+s1[6]+s1[7]+s1[8];
datum := strtodate(s2);
///....
end;
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 13.09.08 23:10 
Alternative: Insert

ausblenden Delphi-Quelltext
1:
2:
3:
Datum := '01012000';
Insert('.', Datum, 3);
Insert('.', Datum, 6);


Sieht doch schöner aus :P

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Sa 13.09.08 23:21 
user profile iconBoldar hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
s2 := s1[1]+s1[2]+'.'+s1[3]+s1[4]+'.'+s1[5]+s1[6]+s1[7]+s1[8];					



Aber hier kann man die Struktur besser erkennen!

Dir fehlt der Sinn für echte Kunst!!!!^^
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: So 14.09.08 01:55 
GTA-Place's Variante ist schon die, die man i.d.R. nutzen sollte, da man sich hier einige unnötige String-Operationen spart.

Und in Bezug auf Kunst: Soll ich mal eben etwas ASM-Pointer-Hacking betreiben ::mrgreen:

_________________
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.
Morpheus1572 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 157

Win XP
Delphi 7
BeitragVerfasst: So 14.09.08 09:26 
@GTA-Place: DAAAAAAANKE für den Happen! Jo, das war genau das was ich für meine Frage als Antwort brauchte. Ich war einfach nicht auf Insert gekommen. Hatte mit Copy() - wie mkinzler meinte - experimentiert, der Code wurde aber nur lännger und schlimmer.

Thx Morph.
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mo 15.09.08 21:42 
user profile iconBenBE hat folgendes geschrieben:

Und in Bezug auf Kunst: Soll ich mal eben etwas ASM-Pointer-Hacking betreiben ::mrgreen:


ja bitte, ist sicher ganz interessant! Aber dann wohl im OT!