dolphin King
asked on
delphi parse string to params
i have this string
oops=Doone&name=data&count =10&ram=ot herdata
i want to parse it to parameters as example
params[1] = oops
Params[2] = doone
Params[3] = name
Params[4] = data
Params[5] = count
Params[6] = 10
Params[7] = ram
Params[8] = otherdata
how can i do that ? in delphi
oops=Doone&name=data&count
i want to parse it to parameters as example
params[1] = oops
Params[2] = doone
Params[3] = name
Params[4] = data
Params[5] = count
Params[6] = 10
Params[7] = ram
Params[8] = otherdata
how can i do that ? in delphi
A quick and dirty solution: I put a button and a edit component. I am using the strngttt.pas library (and old one for turbo pascal, but works in practically every version of delphi). You can find it here: http://files.mpoli.fi/unpacked/software/programm/general/tttsrc51.zip/strnttt5.pas
So, this is my code. I am asumming you´re using these delimiters that are not alphabet characters.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, strngttt, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender : TObject);
var
x : integer;
InpStr : string;
C : char;
TextS : string;
begin
InpStr := Edit1.Text;
for x := 1 to length(InpStr) do
begin
//get rid of all these undesired chars
C := InpStr[x];
if ((ord(C) < 65) or (ord(C) > 122)) then InpStr[x] := ' ';
end;
//now display every word
for i := 1 to WordCnt(InpStr) do
begin
TextS := '';
TextS := ExtractWords(i,1,InpStr);
ShowMessage(TextS);
end;
end;
end.
So, this is my code. I am asumming you´re using these delimiters that are not alphabet characters.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, strngttt, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender
var
x : integer;
InpStr : string;
C : char;
TextS : string;
begin
InpStr := Edit1.Text;
for x := 1 to length(InpStr) do
begin
//get rid of all these undesired chars
C := InpStr[x];
if ((ord(C) < 65) or (ord(C) > 122)) then InpStr[x] := ' ';
end;
//now display every word
for i := 1 to WordCnt(InpStr) do
begin
TextS := '';
TextS := ExtractWords(i,1,InpStr);
ShowMessage(TextS);
end;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
References and examples:
http://docwiki.embarcadero.com/CodeExamples/Berlin/en/RTL.RegExpressionVCL_Sample
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Regular_Expressions