![]() |
Delphi-Quellcode:
Es soll geprüft werden, wann http= kommt und dann soll alles vor der folgenden IP-Adresse weggeschnitten werden, sodass nur noch IP:Port;gopher usw. übrig bleibt.
if (Ord(s[1])>=48) and (Ord(s[1])<=57) then
begin if pos(s,'http=') > 0 then begin Delete(s,6,pos('http=',s)-1-5); s := copy(s, pos('http=',s),length(s)); s := copy(s,1,length(s)-pos(':',s)-1); end else MessageDlg('Kein HTTP-Proxy eingetragen!',mtInformation,[mbOk],0); end else DANN soll ;gopher usw. weggeschnitten werden, sodass ich im Endeffekt alles habe, was in http= drinne steht und ab dem Semikolon alles weg ist. |
Re: Ausschneiden mit Delete
Delphi-Quellcode:
function gettok(const s: string; const tokidx: integer; const c: char): string;
var i, n: integer; LastWasC: boolean; begin result := ''; LastWasC := false; if (s <> '') and (tokidx > 0) then begin n := 0; for i := 1 to length(s) do begin if ((s[i] <> c) and (LastWasC)) or ((s[i] <> c) and (n = 0)) then begin inc(n); if n > tokidx then exit; end; if (s[i] <> c) and (n = tokidx) then result := result + s[i]; LastWasC := s[i] = c; end; end; end; function numtok(const s: string; const c: char): integer; var i: integer; LastWasC: boolean; begin result := 0; if s <> '' then begin LastWasC := false; for i := 1 to length(s) do begin if (s[i] <> c) and ((LastWasC) or (result = 0)) then inc(result); LastWasC := s[i] = c; end; end; end; und dann ganz einfach:
Delphi-Quellcode:
procedure irgendwas;
const DeinString = 'ftp=195.100.85.159:3128;gopher=195.100.85.159:3128;http=195.100.85.159:3128;https=195.100.85.159:3128'; var I: Integer; begin for I := 0 to NumTok(DeinString, ';') do begin if Copy(GetTok(DeinString, I, ';'), 1, 5) = 'http=' then begin Edit1.Text := GetTok(GetTok(DeinString, I, ';'), 1, ':'); // IP In Edit1 Edit2.Text := GetTok(GetTok(DeinString, I, ';'), 2, ':'); // Port in Edit2 Break; end; end; end; |
Re: Ausschneiden mit Delete
Dann kannst du dir das erste if sparen.
Mit "Pos('http',s) > 0" stellst du das sowieso fest. Übrigens sind die Parameter bei dir falsch herum. Schau mal auf meiner Homepage das "Tutorial" zur Stringverarbeitung an. Ich glaube, ich habe das dort sehr übersichtlich erläutert. |
Das geht auch kürzer, mein Arbeitskollege hatte mir das eben vorgemacht, aber irgendwas mach ich falsch :/
Es sind nur noch eine Zeile dazu oder so... Aber ich weiß nicht, was fehlt bzw. was ich falsch mache :( |
Re: Ausschneiden mit Delete
Delphi-Quellcode:
temp : string = 'ftp=195.100.85.159:3128;gopher=195.100.85.159:3128;http=195.100.85.159:3128;https=195.100.85.159:3128';
... delete(temp,1,pos('http=',temp)+ 4); Edit1.Text := copy(temp,1,pos(':',temp) - 1); delete(temp,1,pos(':',temp)); Edit2.Text := copy(temp,1,pos(';',temp) - 1); |
:shock:
Schaps!
Delphi-Quellcode:
if not ((Ord(s[1])>=48) and (Ord(s[1])<=57)) the
begin if pos('http=',s) > 0 then begin Delete(s,1,pos('http=',s)-1); s := copy(s,6,pos(';',s)-6); end else MessageDlg('Kein HTTP-Proxy eingetragen!',mtInformation,[mbOk],0); end; |
Re: Ausschneiden mit Delete
Hallo Leute
vielleicht ist das jetzt eine Holzhammermethode aber warum nicht einfach mit TStrings machen?? hier ist das was ich meine
Delphi-Quellcode:
was spricht dagegen es So zu machen???
procedure TForm1.Button1Click(Sender: TObject);
var sIps : TStrings; i : byte; sOut : string; onlyIp, Port: String; dp : byte; const deinString : string = 'ftp=195.100.85.159:3128;gopher=195.100.85.159:3128;http=195.100.85.159:3128;https=195.100.85.159:3128'; begin sIpS := TStringList.Create; sIps.Delimiter := ';'; sIps.DelimitedText := deinString; sOut := ''; for i:= 0 to sIps.Count-1 do sOut := sOut+sIps.Strings[i]+#13#10; // alle ShowMessage(sOut); // nur http sOut := sIps.Values['Http']; ShowMessage(sOut); dp := pos(':',sOut); onlyIp := midStr(sOut,1,dp-1); Port := midStr(sOut,dp+1,length(sOut)); showMessage(onlyIp+#13#10+port); end; Gruß Stefan |
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:25 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz