Autor Beitrag
unstable
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Do 16.09.04 08:42 
yo,

ich habe einen string:
zb: '46465<text>blablabla</text>'
ich wil den text teil aus diesen string herausholen.
also das blablabla.
es ist schon durch die html tags gekennzeichnet.

bitte hülf.

-_- unstable

_________________
why bother with a sig?
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: Do 16.09.04 08:51 
Probier mal mit der Pos-Funktion. Dann bekommst Du die Stellen der Tags. Ein bisschen was dazu zählen und schon funktioniert die Copy-Funktion.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 16.09.04 10:19 
Siehe Signatur 1. ;-)

Da waren sie wieder, die drei Probleme ...

SCNR,
Jörg

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
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: Do 16.09.04 10:24 
@.Chef:
Schon klar. Aber eine fertige Lösung hilft nicht beim lernen. Wenn unstable nicht weiter kommt, wird er schon was sagen. Dann kann immer noch Sourcen bereit stellen. Ich weiß, dass kann sogar als Einzeiler schreiben.
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 16.09.04 10:28 
Jup, mehr als du gesagt hast, steht ja auch nicht in der Sig. Ich wollte nur noch mal auf den Umstand hinweisen, dass dieses Problem nachweisbar sehr oft auftritt. ;-)

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Do 16.09.04 10:52 
ich habe die antwort schon gefunden:

ausblenden volle Höhe 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:
29:
30:
31:
32:
33:
34:
35:
function getText;
var
  i: Integer;          // Positionszähler im String
  anz: Integer;            // Zeichenanzahl
  text, check : string;
begin
  i := 0;
  inc(i);
  while (s[i] <> '<') do
  begin
    Inc(i);
    if i>anz then Break
  end;

  inc(i);  //'<' überschlagen

  while (s[i] <> '>') do
  begin
    check := check + s[i];
    inc(i);
    if i>anz then Break
  end;

  inc(i);  //'>' überschlagen

  if check = 'text' then
    while (s[i] <> '<') do
    begin
      text := text + s[i];
      Inc(i);
      if i>anz then Break
    end
  else showMessage('string incorrect!');
  Result := text;
end;


ein wenig anders als ihr meintet, aber trotzdem danke für die hilfe :wink:
ein problem war auch, das die zahlen und strings länger/kürzer sein konnten...

thx,
-_-unstable

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

_________________
why bother with a sig?
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 16.09.04 10:56 
Ok, dann jetzt noch der Vollständigkeit halber als Einzeiler. s ist der string:
ausblenden Delphi-Quelltext
1:
s:=Copy(s,Pos('<text>',LowerCase(s))+6,Pos('</text>',LowerCase(s))-Pos('<text>',LowerCase(s))-6);					

Hmm, das sieht schon ziemlich wirr aus ...

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
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: Do 16.09.04 10:57 
Es gibt immer mehrere Lösungswege. Deiner wäre mir nur zu kompliziert. Wenn ich ein stabile Funktion kenne, die mein Problem löst, dann mach ich nix neues. Die Funktionen Pos und Copy solltest Du Dir bei Gelegenheit trotzdem mal ansehen. Die Arbeit wird bei Stringverarbeitung erheblich einfacher.
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Do 16.09.04 11:11 
errr....
.Chef?
könnteste mir den einzeiler mal erklären?
er sieht besser, und vor allem kürzer, aus als meine lösung...
(kenne delphi erst seit ein/zwei wochen...)

thx,
-_-unstable

_________________
why bother with a sig?
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: Do 16.09.04 11:21 
@.Chef: Klasse :rofl:
.Chef hat folgendes geschrieben:
Ok, dann jetzt noch der Vollständigkeit halber als Einzeiler. s ist der string:
ausblenden Delphi-Quelltext
1:
s:=Copy(s,Pos('<text>',LowerCase(s))+6,Pos('</text>',LowerCase(s))-Pos('<text>',LowerCase(s))-6);					

Hmm, das sieht schon ziemlich wirr aus ...
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Do 16.09.04 11:21 
Ok, aber die Funktionsweise von Copy und Pos muss dir klar sein. (ggf. Hilfe!).

Meine Funktion macht aufgeschlüsselt der Reihe nach folgendes: Zunächst brauchen wir den Anfang des Textes, den wir haben wollen (blablabla). Da wir den nicht kennen, müssen wir uns an etwas bekanntem orientieren, dem Text-Tag:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  anfang, laenge : Integer;
  htmlzeile, suchtext : string;
begin
  htmlzeile:='46465<text>blablabla</text>';
  anfang:=Pos('<text>',LowerCase(htmlzeile))+6;

Das LowerCase setzt die Zeile zunächst in Kleinbuchstaben, damit wir auch großgeschriebene Tags erkennen. Pos liefert die Anfangsposition vom Tag zurück. Deshalb muss noch 6 addiert werden, um die Position hinter dem Tag zu erreichen.
ausblenden Delphi-Quelltext
1:
  laenge:=Pos('</text>',LowerCase(htmlzeile))-anfang;					

Analog dazu wird die Position des Ende-Tags bestimmt. Von dieser muss der Anfangswert abgezogen werden, um die Länge des gesuchten Textes zu erhalten, der dann mit Copy herausgeschnitten wird:
ausblenden Delphi-Quelltext
1:
  suchtext:=Copy(htmlzeile, anfang, laenge);					

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
unstable Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 32

windows xp/2000
D5
BeitragVerfasst: Do 16.09.04 12:01 
Klasse .Chef!

danke für die erklärung.
hat mir sehr geholfen :)

thx,
-_-unstable

_________________
why bother with a sig?