Autor Beitrag
arnydaniel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 80

hoffentlich bald Linux
Delphi 6
BeitragVerfasst: Mi 02.02.05 13:48 
Hi,

1. wie kann ich bei einem String das erste Zeichen wegschneiden? Müsste eigentlich mit delete gehn, habs aber nicht hinbekommen!
2. Wie kann ich die Länge (also Anzahl Zeichen) eines Stinges feststellen?
3. Wie kann ich feststellen, ob z.b. ein "," (Komma) in einem String ist?

Danke schonmal im Vorraus

Gruß

_________________
Wenn jeder nur an sich denkt, wird an jeden gedacht.
BernddasBrot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26


D2005
BeitragVerfasst: Mi 02.02.05 13:52 
zu 2.:Length(variablenname)
zu 3.: du überprüfst in einer Schleife jedes einzelne Zeichen mit Variablenname[zaehler]

BernddasBrot
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.02.05 13:55 
zu 1

ausblenden Delphi-Quelltext
1:
delete(deinstring, 1, 1);					


zu 3

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
i:integer;
begin
for i:= 1 to length(deinstring) do if deinstring[i] = ',' then showmessage('Es wurde ein Komma gefunden);
end;


mit pos kann man die position des ersten kommas ermitteln (wenn mehrere drinne sind nur das erste)

ausblenden Delphi-Quelltext
1:
pos(',', deinstring);					
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 02.02.05 13:57 
F34r0fTh3D4rk hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
for i:= 1 to length(deinstring) do if deinstring[i] = ',' then showmessage('Es wurde ein Komma gedfunden);					


oder einfacher: if pos(',',deinstring) > 0 then showmessage('Es wurde ein Komma gedfunden);
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.02.05 13:58 
hab ich doch auch geschrieben, aber wenn er noch die position braucht falls es mehrere sind, ist die for schleife besser

[welcher code steckt eigentlich hinter pos ?] :gruebel:
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 02.02.05 14:05 
F34r0fTh3D4rk hat folgendes geschrieben:
hab ich doch auch geschrieben, aber wenn er noch die position braucht falls es mehrere sind, ist die for schleife besser
dann nimm halt einen integer i, und weis dem die pos zu:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
i:= pos(',',deinstring);
if i > 0 then begin
  showmessage('Es wurde ein Komma gedfunden);
  kill(i);
end;

Zitat:
[welcher code steckt eigentlich hinter pos ?] :gruebel:
<- wie meinst du das ?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 02.02.05 14:10 
F34r0fTh3D4rk hat folgendes geschrieben:
[welcher code steckt eigentlich hinter pos ?] :gruebel:


dieser hier (code stammt aus system.pas und ist Copyright von BORLAND, sollte dieses Zitat unrechtmässig sein bitte um Info...):
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
procedure       _Pos{ substr : ShortString; s : ShortString ) : Integer};
asm
{     ->EAX     Pointer to substr               }
{       EDX     Pointer to string               }
{     <-EAX     Position of substr in s or 0    }

        PUSH    EBX
        PUSH    ESI
        PUSH    EDI

        MOV     ESI,EAX { Point ESI to substr           }
        MOV     EDI,EDX { Point EDI to s                }

        XOR     ECX,ECX { ECX = Length(s)               }
        MOV     CL,[EDI]
        INC     EDI             { Point EDI to first char of s  }

        PUSH    EDI             { remember s position to calculate index        }

        XOR     EDX,EDX { EDX = Length(substr)          }
        MOV     DL,[ESI]
        INC     ESI             { Point ESI to first char of substr     }

        DEC     EDX             { EDX = Length(substr) - 1              }
        JS      @@fail  { < 0 ? return 0                        }
        MOV     AL,[ESI]        { AL = first char of substr             }
        INC     ESI             { Point ESI to 2'nd char of substr      }

        SUB     ECX,EDX { #positions in s to look at    }
                        { = Length(s) - Length(substr) + 1      }
        JLE     @@fail
@@loop:
        REPNE   SCASB
        JNE     @@fail
        MOV     EBX,ECX { save outer loop counter               }
        PUSH    ESI             { save outer loop substr pointer        }
        PUSH    EDI             { save outer loop s pointer             }

        MOV     ECX,EDX
        REPE    CMPSB
        POP     EDI             { restore outer loop s pointer  }
        POP     ESI             { restore outer loop substr pointer     }
        JE      @@found
        MOV     ECX,EBX { restore outer loop counter    }
        JMP     @@loop

@@fail:
        POP     EDX             { get rid of saved s pointer    }
        XOR     EAX,EAX
        JMP     @@exit

@@found:
        POP     EDX             { restore pointer to first char of s    }
        MOV     EAX,EDI { EDI points of char after match        }
        SUB     EAX,EDX { the difference is the correct index   }
@@exit:
        POP     EDI
        POP     ESI
        POP     EBX
end;


du kannst ja mal mit gettickcount prüfen ob die for-schleife oder diese assemblerprozedur schneller durchläuft ^^


Zuletzt bearbeitet von retnyg am Mi 02.02.05 14:12, insgesamt 1-mal bearbeitet
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.02.05 14:10 
ja aber pos liefert immer nur das ERSTE komma, wenn danach noch eines folgt wird dies nicht berücksichtigt bei einer for schleife ist das egal, es sei den man unterbricht sie wenn ein komma gefunden wurde um die performance zu steigern
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mi 02.02.05 14:15 
wie wärs mit einer while-schleife ?
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.02.05 14:18 
ich finde das ist aufwändiger da müsste man ja erstmal ne zählschleife drausmachen, aber for ist ja schon eine.

lass mal warten was arnydaniel dazu sagt, bestimmt ist sein problem schon gelöst und das nächste schon im anmarsch :lol:
MitschL
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Mi 02.02.05 15:30 
Die Frage
Zitat:
3. Wie kann ich feststellen, ob z.b. ein "," (Komma) in einem String ist?

klingt für mich ziemlich eindeutig. Die Antwort darauf kann demnach nur ein Boolean sein.

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 02.02.05 15:36 
ja und ? das kann man dann doch einfach abfragen