Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.02.06 20:47 
Hallo ich habe den String 's'. So, nun will ich prüfen, ob die Zeichen bis zu einem '#' in s '13' sind.

Also: wenn alle zeichen von s bis zu '#' gleich '13' dann tue irgendwas.

Welche Funktion muss ich nehmen? (hab es schon mit copy probiert)

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 20:55 
wie wärs mit pos('#',s) ?
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: Sa 18.02.06 20:55 
ein Zeichen kann doch nicht '13' sein :rofl:
Irgendwie versteh ich da was nicht :gruebel:


greetz

_________________
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.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 20:56 
ich dachte er meinte die anzahl der zeichen :lol:
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: Sa 18.02.06 20:59 
Kann auch sein.. dann würd ich einfach if  s[14] = '#' then //machwas nehmen

_________________
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.


Zuletzt bearbeitet von Born-to-Frag am Sa 18.02.06 21:05, insgesamt 1-mal bearbeitet
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 18.02.06 21:04 
Hallo,
und wenn der String so aussieht?
ausblenden Delphi-Quelltext
1:
s :=  'abcde#wertert#';					

dann besser so:
ausblenden Delphi-Quelltext
1:
2:
if Pos('#',s) = 14 then  
  showmessage('vor "#" sind 13 Zeichen');

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
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: Sa 18.02.06 21:06 
Genaugenommen ist aber # doch auch ein Zeichen :nut: ^^

_________________
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.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.02.06 21:09 
Sorry Jungs - meine Schuld

Es sollen aus s alle Zeichen ausgelesen werde, die sich vor dem '#' befinden. Das mit der 13 ist unnütz :autsch:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.02.06 21:12 
Ich meinte das so:
auslesen alle Zeichen von s vor der Raute.
Dann prüfen ob dieser ausgelesene String gleich '13' ist. Also keine Zahl - '13' als String.
Und wenns so ist, dann machwas. Ich weiß nur nich, wie man das ausliest. Ich muss jetzt essen, dann probier ichs mal mit pos.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 18.02.06 21:18 
user profile iconKoller hat folgendes geschrieben:
.... Ich muss jetzt essen, dann probier ichs mal mit pos.

Eine gute Idee. Und dann noch "pos" und zwei Vergleiche oder "copy" und ein Vergleich...

_________________
Na denn, dann. Bis dann, denn.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 21:22 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var i: integer;
    s,Text: string;
begin
 i := pos('#',Text);
 s := copy(Text,0,i-1);

If s = '13' then ...


(ungetestet)
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 18.02.06 21:26 
user profile iconNoTVerYEvilPzYchO hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var i: integer;
    s,Text: string;
begin
 i := pos('#',Text);
 s := copy(Text,0,i-1);

If s = '13' then ...


(ungetestet)

Das merkt man ...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var i: integer;
    s,Text: string;
begin
 i := pos('#',Text);
 If i=0 Then Raise Exception.Create('"#" kommt im Text nicht vor');
 // s := copy(Text,0,i-1); // Stringindizes sind 1-basiert. Und er will doch prüfen, ob *NACH* dem # eine 13 steht
 s := Copy (Text, i+1,2);
 If s = '13' then ...

Oder noch einfacher:
ausblenden Delphi-Quelltext
1:
If Pos ('#13',Text)<>0 Then ...					

Wenn man nur wissen woll, ob nach dem # eine 13 kommt. Mich dünkt, er will nach CR (carriage return, #13) prüfen...

_________________
Na denn, dann. Bis dann, denn.
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 18.02.06 21:30 
user profile iconKoller hat folgendes geschrieben:

auslesen alle Zeichen von s vor der Raute.
Dann prüfen ob dieser ausgelesene String gleich '13' ist. Also keine Zahl - '13' als String.


mhm.. ich dachte er meinte "13" vor der raute :roll:

user profile iconalzaimar hat folgendes geschrieben:
If i=0 Then Raise Exception.Create('"#" kommt im Text nicht vor');


Warum eine exception auslösen? ich würds mit showmessage machen :roll:
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 18.02.06 21:52 
Mann o mann, ick werd alt. Nee, ich hab voll die Erkältung, die offensichtlich vor meinem Hirn nicht haltmacht.
Vor, klar. Peinlich. Egal.

Selbst dann deine Lösung nicht ganz korrekt (aber wenigstens verstehe ich sie dann).
Aber erstmal die Exception erklären: Die bricht, im Gegensatz zu einem Showmessage, die Programmausführung ab. Und die Routine darf dann nicht weiter machen. Die Exception kann man ohne Problem im Aufruf abfangen. Das ist imho legaler Programmierstil.

So. 13 VOR der Raute. Direkt davor? Egal:
Direkt davor?
ausblenden Delphi-Quelltext
1:
If Pos ('13#', Text)>0 Then ...					

Nicht direkt davor?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
p := Pos ('#', Text);
If p=0 then ....
For i:=1 to p-2 do
  if Copy (Text, i,2)='13' Then  
    ShowMessage ('Irgendwo vor der Raute gibts eine 13');

_________________
Na denn, dann. Bis dann, denn.
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.02.06 22:01 
Was ich machen will:
Es werden per Sockets Strings gesendet. Es gibt verschiedene Befehle. (1=reboot; 2=shutdown .. 10=changebackground) Es wird folgendes egsendet: '13#dateipfad'.
Und nun muss ich in der Prüfprozedur, die diesen String zerpflückt, prüfen, was vor der Raute steht, um den Befehl zu kenn.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Sa 18.02.06 22:07 
Aha. Dann so:
ausblenden Delphi-Quelltext
1:
2:
p := Pos ('#', Text);
Cmd := Copy (Text,p-2,2);

(Ohne Fehlerprüfung)

_________________
Na denn, dann. Bis dann, denn.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Sa 18.02.06 22:35 
Hallo,
funktioniert aber nur wenn die Zahl vor '#' 2-stellig ist,
besser so:
ausblenden Delphi-Quelltext
1:
2:
p := Pos ('#', Text);  
Cmd := Copy (Text,1,p-1);


[OT]
user profile iconalzaimar hat folgendes geschrieben:
Nee, ich hab voll die Erkältung
gute Besserung :wink: [/OT]

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 19.02.06 10:17 
user profile iconLannes hat folgendes geschrieben:
Hallo,
funktioniert aber nur wenn die Zahl vor '#' 2-stellig ist,
besser so:
ausblenden Delphi-Quelltext
1:
2:
p := Pos ('#', Text);  
Cmd := Copy (Text,1,p-1);


Nee, so doch auch nicht... Das Kommando ist doch nicht alles vor dem "#" . Is doch echt geil, wie man sich an so einem Problem totcoden kann :oops:

Also, jetz mal der offizielle Kommando-Vor-Der-Raute-Extrakt-o-mat. Ich sammle alle Ziffern VOR der Raute ein:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Function TheCommandInFrontOfTheHash(Const aString : String) : String;
Var
  p,q,r : Integer;

Begin
  p := Pos('#',aString);
  If p=0 Then
    Raise Exception.Create('Keine Raute im String');
  q := p - 1;
  Result := '';
  While (q > 0And IsDigit (aString[q]) do Begin
    Result := aString[q] + Result;
    dec (q);
    End;
End;    
// Falls IsDigit unbekannt ist, dann durch "(aString[q] in ['0'..'9'])" ersetzen

user profile iconLannes hat folgendes geschrieben:

[OT]
...gute Besserung :wink: [/OT]

Danke, kanns gebrauchen :eyes:

Was lehrt uns das:
1. Kommandos möglichst uniform (also feste Zeichenlänge).
2. Das Kommando-Escape-Zeichen ('#') VOR die Kommandos setzen.

Dann reduziert sich o.g. Code gewaltig.

_________________
Na denn, dann. Bis dann, denn.
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 19.02.06 14:06 
Hallo,
user profile iconalzaimar hat folgendes geschrieben:
...
Nee, so doch auch nicht... Das Kommando ist doch nicht alles vor dem "#"
Das Kommando ist alles vor dem '#',
denn:
user profile iconKoller hat folgendes geschrieben:
Ich meinte das so:
auslesen alle Zeichen von s vor der Raute.
Dann prüfen ob dieser ausgelesene String gleich '13' ist.


user profile iconalzaimar hat folgendes geschrieben:
Is doch echt geil, wie man sich an so einem Problem totcoden kann
finde ich auch.
Fazit: Mit der Qualität/Eindeutigkeit der Frage steigt die Qualität/Eindeutigkeit der Antwort :angel:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Marco D. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 19.02.06 14:10 
Jo das stimmt :D
Ich hab mich aber auch dumm ausgedrückt, das gebe ich zu.
Es ist richtig, dass ich im Grunde aus dem String s einfach alle Zeichen extrahieren möchte.
Hier stehen so viele Postings - welches ist nun richtig?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot