Autor Beitrag
Sauger Chris
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 23.12.06 12:37 
moin :)

und zwar möchte ich gern einen string trennen der zwischen den oben genannten strings steht
beispiel:

<title>Morgen ist so ein wunder schöner tag</title>

die länge von dem string zwischen <title> </title> variiert und das ist mein problem.

ps.
hab im forum gesucht aber hat mir nicht weiter geholfen


danke für eure hilfe und ein frohes fest =)

mfg sauger chris
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 23.12.06 12:43 
Einfach Positionen von <title> und </title> suchen dann 1. Position + 8 bis 2. Position -1 verwenden.

_________________
Markus Kinzler.
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Sa 23.12.06 12:44 
Du kannst mit Hilfe der Funktion Pos() (Member von String) das erste Vorkommen eines Zeichens in einem String ermitteln.

Such nach "<title>", dann hast du die Anfangsposition-8 und such nach "</title>", dann hast du die Endposition deines Strings+1. Den kannst du dann per SubString extrahieren!

EDIT: Mist, zu langsam ...
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Sa 23.12.06 12:46 
SO kommste auf die Länge:
ausblenden Delphi-Quelltext
1:
l:=Pos(s,'</title>')-Pos(s,'<title>')-7;//7=length('<title>')					


//EDIT: Viel zu lahm :roll:

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Sa 23.12.06 13:20 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
function GetTitleFromHTML(HTMLDoc: String):String;
var
I: Integer;
Found: Boolean;
html: TStringList;
begin
 html := TStringList.create;
 html.loadfromfile(htmldoc);
 i := 0;
 found := false;
 while not found do
  begin
   if pos('<title>', html.strings[i]) > 0 then
    begin
     Result := copy(html.strings[i], pos('<title>', html.strings[i]) + 7, (pos('</title>', html.strings[i]) - pos('<title>', html.strings[i]) - 7));
     Found := true;
    end
   else
    begin
     Inc(i);
    end;
  end;
html.free;
end;

//Anwendungsbeispiel:
if opendialog1.execute then
 showmessage(GetTitleFromHTML(opendialog1.filename));
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 23.12.06 13:45 
ok danke geht nur noch ein kleines prob wie mache ich es das er mir
alle strings anzeigt
weil es sind ein paar strings zwischen <titel> </titel>


mit ner for schleife nur wie genau

:)

ansonsten danke euch allen :-)
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Sa 23.12.06 13:47 
user profile iconSauger Chris hat folgendes geschrieben:
weil es sind ein paar strings zwischen <titel> </titel>

Wie darf man das verstehen? Du hast mehrere <title>-Tags?
Dann handelt es sich vermutlich um XML oder etwas ähnliches.

In dem Fall: Pos() liefert dir das erste Vorkommen!
Also schneidest du einfach alles bis einschl. dem ersten Vorkommen aus deinem String heraus, nachdem du es gefunden hast. Wenn du dann wieder Pos() verwendest, kriegst du halt das nächste Vorkommen, weil das ursprünglich erste ja nicht mehr in deinem String enthalten ist. Und so weiter dann halt ...
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 23.12.06 13:47 
Von Pos gibt es auch noch ne Version mit Ofset (PosEx)

_________________
Markus Kinzler.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 23.12.06 13:47 
Andreas: Warum einfach, wenn es auch kompliziert geht :lol:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function GetTitle(HTML: String): String;
begin
  Result := Copy(HTML, Pos('<title>', HTML) + 7, Pos('</title>', HTML) - Pos('<title>', HTML) - 7);
end;

Musst noch etwas mit den markierten Zahlen spielen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 23.12.06 13:48 
War Quatsch, Sorry.

_________________
Blackheart666
Der Irrsinn ist bei Einzelnen etwas Seltenes, - aber bei Gruppen, Parteien, Völkern, Zeiten die Regel. (Friedrich Nietzsche)
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 23.12.06 15:03 
so sieht das von mir aus jetzt soll er alle strings zwischen <title> </title>
aus geben

bei den bisherigen cods gib der mir nur das erste aus das zwischen <title> </title> steht

hab aber mehr die er aus geben soll :-)

[highlight]
<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.07.|12:55] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.08.|12:56] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.09.|12:57] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.10.|12:58] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.11.|12:59] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.12.|12:60] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>
[/highlight]
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Sa 23.12.06 15:05 
Wie gesagt: Schau dir mal meinen Ansatz an, oder auch den von user profile iconmkinzler.

Allerdings finde ich meinen Ansatz eleganter. Denn dadurch, dass der String immer kleiner Wird, muss nicht immer wieder der gesamte Text durchsucht werden. Das macht die Lösung imho performanter.
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Sa 23.12.06 15:11 
user profile iconSauger Chris hat folgendes geschrieben:
so sieht das von mir aus jetzt soll er alle strings zwischen <title> </title>
aus geben

bei den bisherigen cods gib der mir nur das erste aus das zwischen <title> </title> steht

hab aber mehr die er aus geben soll :-)

[highlight]
<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.07.|12:55] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.08.|12:56] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.09.|12:57] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.10.|12:58] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.11.|12:59] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>

<item rdf:about="http://www.hompage.de/index.php?inc=2.1&amp;id=30971">
<link>www.hompage.de/index...id=30971</link>;
<title>[23.12.|12:60] die welt geht heute unter</title>
<description>die welt geht heute unter - Ratings: -/-/-</description>
</item>
[/highlight]


Wieso nicht gleich einen vorhandenen XML-Parser bemühen? >> Suche in: Delphi-Forum, Delphi-Library XML TUTORIAL <<
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 23.12.06 17:42 
in ner anderen sprache ist das mit den wenigen zeilen getan


ausblenden Quelltext
1:
2:
3:
4:
5:
6:
if (*<item rdf:about="*">* iswm %xrel_temp) { set %xrel_i 1 }
  if (%xrel_i == 1) && (*<link>*</link>* iswm %xrel_temp) { set %xrel_a $replace($gettok($gettok(%xrel_temp,2,62),1,60),&,&) }
  if (%xrel_i == 1) && (*<title>*</title>* iswm %xrel_temp) { set %xrel_b $gettok($gettok(%xrel_temp,2,62),1,60) }
  if (*</item>* iswm %xrel_temp) {
    unset %xrel_i | sockclose xrel 
    if ($remove(%xrel_b,$chr(32)) != %rel) { set %rel $remove(%xrel_b,$chr(32)) | amsg 9[output]11 %xrel_b 15*14 $+(,%xrel_a,) | unset %xrel* }



muß das doch mit delphi auch zu schaffen sein :-(

brauch nur noch n code wo alle strings zwischen <title> </title> anzeigt mehr nicht ??


der code gibt nur ein string aus der zwischen <title> </title> steht

ausblenden Delphi-Quelltext
1:
2:
3:
4:
function GetTitle(HTML: String): String
begin 
  Result := Copy(HTML, Pos('<title>', HTML) + 7, Pos('</title>', HTML) - Pos('<title>', HTML) - 7); 
end;


Moderiert von user profile iconChristian S.: Code- und Delphi-Tags eingefügt


Zuletzt bearbeitet von Sauger Chris am Sa 23.12.06 17:44, insgesamt 1-mal bearbeitet
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 23.12.06 17:44 
Dü könntest auch einen (RDF-)Parser verwenden.
z.B. www.philo.de/rdf/

_________________
Markus Kinzler.
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 24.12.06 00:50 
Hallo,
user profile iconSauger Chris hat folgendes geschrieben:
muß das doch mit delphi auch zu schaffen sein :-(
was hast Du denn bisher versucht?

Kannst es mal damit versuchen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
procedure ExtractStrings(sEing: String;Tags: array of String;sAusg: TStrings);
var z,i,a,x : Integer;
begin
  x := 0;
  a := 0;
  i := 1;
  for z := 1 to Length(sEing) do
    begin
    if sEing[z] = Tags[x][i] then
      inc(i)
      else
        i := 1;
    if i = Length(Tags[x])+1 then
      if a = 0 then
        begin
        inc(x);//umschalten auf End-Tag
        a := z+1;
        end
        else
          begin
          dec(x);//umschalten auf Start-Tag
          sAusg.Add(Copy(sEing,a,z-a-Length(Tags[x])));
          a := 0;
          end;
    end;
end;


der Aufruf:
ausblenden Delphi-Quelltext
1:
  ExtractStrings(Memo1.Text,['<title>','</title>'],Memo2.Lines);					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Sauger Chris Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 228

Win XP, Linux SuSE 9.2
Delphi 4,Delphi 7 Ent.
BeitragVerfasst: Sa 13.01.07 10:40 
danke

ps. so einfach kans gehn :D