Autor Beitrag
Ace87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Fr 22.09.06 12:33 
Wie kann ich überprüfen, ob der Text mit einem bestimmten wort anfängt??
Zum Beispiel, wenn ich den Satz 'Wie geht dir' in einem Edit habe und überprüfen will,
ob er mit 'Wie' anfängt.

gibt es du einen Befehl für oder kann mir jemand irgend wie helfen

Mit freundlichen Grüßen

David
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 22.09.06 12:38 
schau dir mal Suche in der Entwickler-Ecke POS an. damit könntest du nach dem ersten leerzeichen suchen und dann mit Suche in der Entwickler-Ecke COPY das erste wort (also alles vor dem ersten leerzeichen) in eine stringvariable packen... und diese kannst du dann vergleichen.

_________________
Anonymes Eckenkind
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.09.06 12:41 
Grundlagen für die Stringverarbeitung findest du hier.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 22.09.06 12:42 
Als Alternative gibts noch die Funktionen AnsiStartsStr und AnsiStartsText.

_________________
We are, we were and will not be.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 22.09.06 12:43 
Moin!

DOH hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
function StrLComp(const Str1, Str2: PChar; MaxLen: Cardinal): Integer;					


Beschreibung

StrLComp vergleicht bis zu MaxLen Zeichen der beiden Strings Str1 und Str2. In der folgenden Tabelle sind die Rückgabewerte erläutert:

Rückgabewert Bedingung

<0 Str1 kommt vor Str2
=0 Str1 ist mit Str2 identisch
>0 Str1 kommt nach Str2

Hinweis: Verwenden Sie bei der Arbeit mit internationalen Zeichen die Funktion AnsiStrLComp.

Mehr in der DOH. ;)

cu
Narses

//EDIT: Hups... schnarch... :gaehn: bin ich langsam... ;)

_________________
There are 10 types of people - those who understand binary and those who don´t.
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Fr 22.09.06 12:53 
danke ;)

hast mir sehr geholfen
ging ja einfach

ausblenden Delphi-Quelltext
1:
if  (pos('Hi',Edit1.Text) > 0) then					
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 22.09.06 12:56 
jau...
wobei du jetzt aber im gesamten edit suchst...
um das erste wort nur zu kriegen könntest du aber mit =1 abfragen ;-)

_________________
Anonymes Eckenkind
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.09.06 13:02 
Hi Miri,

ich will daraus jetzt keine Fachdiskussion machen, aber das ist zeimlich egal. Wenn "Pos" verwendet wird, gibt die Funktion sowieso genau einen Wert zurück und arbeitet auf jeden Fall genau gleich. Ob ich diesen Wert nun auf exakt "1" oder größer "0" vergleiche, dürfte sich im kaum messbaren Bereich bewegen. :wink:
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Fr 22.09.06 13:03 
aso ok danke

jetzt habe ich es genau

thx an alle
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 22.09.06 13:11 
@jasocul: Da muss ich aber Miri in Schutz nehmen :mrgreen:. Wenn man wissen möchte, ob ein Text mit einem bestimmten Text anfängt, muss man bei Verwendung von Pos auf "= 1" überprüfen. Denn dann ist die Position des Subtextes =1, also am Anfang. Pos('wie', 'Gib mir mein Geld wieder') liefert einen Wert größer Null, aber der Satz fängt nicht mit "wie" an. ;-)

(Oder hab ich da jetzt was falsch verstanden? :gruebel:)

_________________
We are, we were and will not be.
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 22.09.06 13:13 
@Gausi

danke :)
und der reaktion von ace87 nach zu urteilen, haben wir ihn richtig verstanden ;-)

_________________
Anonymes Eckenkind
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Fr 22.09.06 13:20 
Sch... . Zum Glück ist bald Wochenende. Dann habe ich Zeit mein Brett vom Kopf abzuschrauben.
Sorry.

Dann aber zur Optimierung:
ausblenden Delphi-Quelltext
1:
if  (pos('Hi',Trim(Edit1.Text)) = 1) then					

Sonst könnten führende Leerzeichen zum Problem werden.

EDIT:
Hinweis vonuser profile iconMiri eingebaut.


Zuletzt bearbeitet von jasocul am Fr 22.09.06 15:02, insgesamt 1-mal bearbeitet
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Fr 22.09.06 13:58 
wieso könnten führende Leerzeichen zum Problem werden????
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 22.09.06 13:58 
Dann aber bitte das Brett ganz abschrauben: :tongue:

ausblenden Delphi-Quelltext
1:
if  (pos('Hi',Trim(Edit1.Text)) = 1) then					


Pos liefert 0 zurück, wenn der Text nicht enthalten ist. Indizierung bei Strings fängt bei 1 an.

_________________
We are, we were and will not be.
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Fr 22.09.06 14:00 
ganz einfach pos('Hallo', 'Hallo Ace87') liefert 1 zurück, aber pos('Hallo', ' Hallo Ace87') liefert 2 zurück... (ist ja erst das 2. zeichen, wo's losgeht... und trim() entfernt führende leerzeichen :)

_________________
Anonymes Eckenkind
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Fr 22.09.06 14:43 
hey das ist ja noch besser
vielen dank :)
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Fr 22.09.06 15:47 
Vielleicht noch etwas schneller (aber dafür 4 Zeichen Länger):
ausblenden Delphi-Quelltext
1:
if  (pos('Hi',TrimLeft(Edit1.Text)) = 1) then					

;)

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Jukka
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 107

Win XP Pro
Delphi 7
BeitragVerfasst: Fr 22.09.06 16:46 
ausblenden Delphi-Quelltext
1:
if copy(edit1.text,1,2) = 'Hi' then ...					


das ist doch dafür besser, er testet die ersten 2 zeichen, wenn das Hi ist dann trifft das zu, pos sucht imemrhin im ganzen edit
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Fr 22.09.06 16:50 
aber dann noch Trim benutzen @Jukka ;)

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.