Autor Beitrag
Tanrek
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34



BeitragVerfasst: Mo 01.08.05 14:30 
jau... eigentlich sagt der thementitel alles... ich möchte einen String Teilweise auslesen...
ich habe z.b. ein paar strings, die so aussehen:
TestA
TestB
TestC
ich möchte diese Strings jetzt so benutzen können, dass es egal ist, ob hinten ein A, B oder so steht... da können nämlich auch 1, 2 oder YX, GH stehen. ich will halt nur nach dem Test prüfen. geht das überhaupt?

mfg tanrek
noidic
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 851

Win 2000 Win XP Vista
D7 Ent, SharpDevelop 2.2
BeitragVerfasst: Mo 01.08.05 14:32 
Schau dir mal die hilfe zum Befehl pos an. Dürfte dir helfen, damit haste direkt auch die Info, wo im String das gesuchte Fragment ist.

Gruß

noidic

_________________
Bravery calls my name in the sound of the wind in the night...
snoopyonline
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 38



BeitragVerfasst: Do 04.08.05 22:51 
und falls du es doch anders meinst: der Befehl "copy" hilft da auch manchmal weiter:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var gleich : boolean;
text1,text2 : string;

begin
text1 := 'TestA';
text2 := 'TestB';
if copy(text1,1,4) = copy(text2,1,4) then gleich := true;
end;


Das Ergebnis von "gleich" wäre in diesem Falle true, da in beiden Strings nur die Buchstaben von 1 bis 4 verglichen werden.

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt.
Logikmensch
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 390

Win XP
Delphi 2007 Prof., XE2, XE5
BeitragVerfasst: Fr 05.08.05 04:33 
Titel: eine weitere Möglichkeit
Hallo,

eine weitere, gerne eingesetzte Möglichkeit ist diese:

if pos('TEST',uppercase(s))=1 then...

oder:

if uppercase(copy(s,1,4))='TEST' then...

Damit wäre zweifelsfrei geprüft, dass der Inhalt von S mit dem Wort Test, test, TEST, aber auch TeSt beginnt.

Gruß,

Claus.