Home > Back-end >  Delphi intercept string
Delphi intercept string

Time:09-24

https://www.baidu.com/s? Dfasdfasdfasdfasdfas this is I want to capture the third/after a string of a string, before no s? Dfasdfasdfasdfasdfas

CodePudding user response:

 
Procedure TForm1. BitBtn1Click (Sender: TObject);
Var
S: a string;
L: TStringList;
I: integer;
The begin
S:='https://www.baidu.com/s? Dfasdfasdfasdfasdfas';
L:=TStringList. Create;
L.D elimiter:='/';
L.D elimitedText:=s;
For I:=0 to l.C do mount - 1
Memo1. Lines. The Add [I] (l);
FreeAndNil (l);
end;


I haven't written a Delphi code, that you give it a try

CodePudding user response:

 unit Unit1; 

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
Edit1: TEdit;
Edit2: TEdit;
For: TButton;
Button2: TButton;
Procedure Button1Click (Sender: TObject);
Procedure Button2Click (Sender: TObject);
Private
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}


The function getS (s: string) : string;
Var I, j: integer;
The begin
Result:=';
J:=0;
For I:=1 to Length (s) do
If [I]='/' S then j:=I;
If j> 0 then the Result:=Copy (S, J + 1, Length (S) - J);
end;

Procedure TForm1. Button1Click (Sender: TObject);
The begin
Edit1. Text:='https://www.baidu.com/s? Dfasdfasdfasdfasdfas';
end;

Procedure TForm1. Button2Click (Sender: TObject);
The begin
Edit2. Text:=getS (Edit1. Text);
end;

End.


For reference only,

CodePudding user response:

Arr: TArray;
S: a string;

S:='https://www.baidu.com/s? Dfasdfasdfasdfasdfas';
Arr:=s.S plit (['/'], ExcludeEmpty);
Showmessage (Arr [High (Arr)]);

CodePudding user response:

Delphi low version directly put the string into a TstringList format, want to take which one can take what a

Stringlist:=stringreplace (' https://www.baidu.com/s? Dfasdfasdfasdfasdfas', '/', # 13, [rfReplaceAll]);
Showmessage (stringlist [2]);

Delphi version with 3rd floor.

CodePudding user response:

Using the copy function
  • Related