Autor Beitrag
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Sa 23.06.07 19:04 
Hi,
ich hab mal ein komisches Problem:
Ich habe diesen code. S soll die suchmaske sein und zwar ('String',htmlcode) (htmlcode is das file, daran liegts nich)
normal sieht der code so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var
s: integer;
begin
Quellcodepfad:=ExtractFilePath(ParamStr(0))+'temp3.html';

LoadStringfromFile(quellcodepfad,htmlcode);

s:=pos('http://rs31.rapidshare.com/access,htmlcode);

damit geht es auch. Aber leider is dieses rs31 dynamisch und das muss ich angleichen.
also hab ich das mal so gemacht:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
var
s: integer;
surlmake: string;
begin
Quellcodepfad:=ExtractFilePath(ParamStr(0))+'temp3.html';

LoadStringfromFile(quellcodepfad,htmlcode);
surlmake:=form2.label11.caption+'access'; //label11 is http://rs31.rapidshare.com/ und access wird angehängt
label10.caption:=surlmake;  //zur kontrolle: es wird http://rs31.rapidshare.com/access angezeigt!
s:=pos(surlmake,htmlcode); // es soll halt den surlmake string im htmlcode lesen
label12.caption:=inttostr(s); // s=integerwert den lass ich mir mal anzeigen

damit gehts wiederum nicht. In label12 hab ich mir den wert ja anzeigen lassen. bei der 1. methode, die funktioniert, ist er 6124 oder so. Bei der 2., die nicht funktioniert - 0. Warum is das so?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.06.07 19:34 
Moin!

Mit einem regulären Ausdruck ist das ganz leicht :arrow: Suche in: Delphi-Forum, Delphi-Library TREGEXPR ;) Probier´s doch halt mal, sind doch Beispiele genug dabei und hier im Forum. :les:

cu
Narses

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



BeitragVerfasst: Sa 23.06.07 20:15 
würde dann z.B. bei Const CoordPatern = 'rs+[0-9]+[0-9]+rapidshare.com/access' sein?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.06.07 20:33 
Moin!

Probier mal "rs\d*\.rapidshare\.com/access". :idea:

cu
Narses

\\EDIT: Pattern angepasst

_________________
There are 10 types of people - those who understand binary and those who don´t.


Zuletzt bearbeitet von Narses am Sa 23.06.07 22:34, insgesamt 1-mal bearbeitet
Hendi48 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Sa 23.06.07 20:38 
ich hab jetzt
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
function getserver(const AInputString: string): string;
const
  CoordPattern = 'rs*\.rapidshare\.com/access';
var
  r : TRegExpr;
begin
  Result := '';
  r := TRegExpr.Create;
  try
    r.Expression := CoordPattern;
    Result := r.Replace(AInputString,'http://rs--.rapidshare.com/access');
  finally
    r.Free;
  end;
end;

und im Button
ausblenden Delphi-Quelltext
1:
label5.caption:=getserver('http://rs--.rapidshare.com/access');					

so funktioniert das nich is vielleicht 'http://rs--.rapidshare.com/access' falsch?
vor das rs* muss noch http://
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 23.06.07 22:33 
Moin!

OK, ich hab´s jetzt damit getestet:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.Button1Click(Sender: TObject);
  var  
    RE: TRegExpr;  
begin
  RE := TRegExpr.Create;
  try
    try
      RE.Expression := 'http://rs\d*\.rapidshare\.com/access';
      if RE.Exec(Edit1.Text) then // Edit1: die zu durchsuchende Zeichenfolge
        Edit2.Text := RE.Match[0] // Edit2: Ergebnisausgabe
      else
        Edit2.Text := 'kein Treffer';
    except
      Edit1.Text := 'Fehler: '+Exception(ExceptObject).Message;
    end;
  finally
    RE.Free;
  end;  
end;

cu
Narses

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



BeitragVerfasst: So 24.06.07 13:36 
jo danke, so funzts. Nur ich hatte noch vergessen das nach access noch 5, 6 oder 7 zahlen kommen und dann .jpg (.jpg is immer gleich). Kann man noch irgendwie machen das der dann noch weiter geht bis zum g (von dem jpg)?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 24.06.07 15:30 
Moin!

user profile iconHendi48 hat folgendes geschrieben:
jo danke, so funzts.

Bitte. ;)

user profile iconHendi48 hat folgendes geschrieben:
Nur ich hatte noch vergessen das nach access noch 5, 6 oder 7 zahlen kommen und dann .jpg (.jpg is immer gleich). Kann man noch irgendwie machen das der dann noch weiter geht bis zum g (von dem jpg)?

Ja, kann man. :P Schau mal ein bischen in die Doku, Kapitel Syntax der regulären Ausdrücke, da steht, wie das geht (und eine Vorlage hast du ja jetzt oben schon). 8) :D Du schaffst das schon... :zustimm:

cu
Narses

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



BeitragVerfasst: So 24.06.07 16:20 
:D ich habs:
ausblenden Delphi-Quelltext
1:
RE.Expression := 'http://rs\d*\.rapidshare\.com/access\d*\.jpg';					

Nochmal danke für die Hilfe :!: