Autor Beitrag
kostenix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mo 24.05.04 12:01 
hallo,

gibt es eine möglichkeit einen string nach zb '12345' an einer bestimmten position zu durchsuchen?

if POS('12345', Textzeile) > 0 then begin....

das geht auch aber es liefert alle strings zurück die den suchstring irgendwo enthalten und nicht nur da wo ich eigentlich suchen will...

mein 12345 steht an position 129-133 des strings...


bin für jede hilfe dankbar


Zuletzt bearbeitet von kostenix am Mo 24.05.04 13:17, insgesamt 1-mal bearbeitet
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mo 24.05.04 12:04 
Da Pos ja den Index des ersten Zeichens des gesuchten Begriffs zurückgibt, sollte folgendes funktionieren:

ausblenden Delphi-Quelltext
1:
2:
If Pos('12345', Textzeile) = ErwartetePosition
 then ...

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
FaTaLGuiLLoTiNe
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 200
Erhaltene Danke: 5

Windows 7, Windows 8.1
Delphi XE
BeitragVerfasst: Mo 24.05.04 12:06 
Hmm, das klappt natürlich nicht wenn '12345' schon vorher einmal im Text vorkommt, da Pos nur das erste Vorkommen des Suchbegriffs ermittelt. Ansonsten geht es natürlich mit Copy:

ausblenden Delphi-Quelltext
1:
2:
If Copy(Textzeile, ErwartetePosition, 5) = '12345'
 then ...

_________________
<< FaTaLGuiLLoTiNe >>
Rhinoceroses don't play games!
kostenix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mo 24.05.04 12:18 
wie würde der quellcode aussehen wenn ich diese '12345' nur an der stelle 129 bis 133 erwarte?

1 = zeichenposition im string: 129
2 = zeichenposition im string: 130
3 = zeichenposition im string: 131
4 = zeichenposition im string: 132
5 = zeichenposition im string: 133

diese zeichen positionen müssen so belegt sein, dann ist es true...

meine zeilen werden in einer for schleife einzeln geladen und dann durchsucht....
MartinPb
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 698



BeitragVerfasst: Mo 24.05.04 12:21 
ausblenden Delphi-Quelltext
1:
if POS('12345', Textzeile) = 129 then begin....					

_________________
Gruß
Martin
kostenix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 26



BeitragVerfasst: Mo 24.05.04 12:27 
super! funktioniert!

danke schön
IngoD7
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 629


D7
BeitragVerfasst: Mo 24.05.04 12:52 
Titel: Re: string durchsuchen nach position
kostenix hat folgendes geschrieben:
hallo,

gibt es eine möglichkeit einen string nach zb '12345' an einer bestimmten position zu durchsuchen?


Ja, mit PosEx.