This is a very quick example put together. I'm sure someone can improve upon it. But it should parse the conn string without regard to order and embedded values. It assumes a proper connection string. Probably missed something though:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
StrArr = Array[0..1] of string;
ConnArr = Array of StrArr;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
function SplitConn(AStr: string): ConnArr;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
function TForm1.SplitConn(AStr: string): ConnArr;
var
ch: char;
inval: boolean;
inquote: boolean;
quoteval: char;
cnt: integer;
start: integer;
len: integer;
begin
inval := false;
inquote := false;
quoteval := ' ';
cnt := 0;
start := 1;
len := 0;
for ch in AStr do
begin
if not inquote then
begin
if (ch = '"') or (ch = '''') then
begin
inquote := true;
quoteval := ch;
Inc(start);
end
else if ch = '=' then
begin
// end of first item
Inc(cnt);
SetLength(Result, cnt);
Result[cnt-1][0] := Copy(AStr, start, len);
inval := true;
start := start + len + 1;
len := 0;
end
else if ch = ';' then
begin
if inval then
begin
// end of second item
Result[cnt-1][1] := Copy(AStr, start, len);
inval := false;
start := start + len + 1;
len := 0;
end
else
// most likely semi after closing quote so skip past
Inc(start);
end
else
Inc(len);
end
else
begin
if quoteval = ch then
begin
// end of second item
Result[cnt-1][1] := Copy(AStr, start, len);
inval := false;
start := start + len + 1;
len := 0;
inquote := false;
quoteval := ' ';
end
else
Inc(len);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
data: ConnArr;
str: string;
I: integer;
begin
str := '';
data := SplitConn(Edit1.Text);
for I := 0 to Length(data) - 1 do
str := str + data[I][0] + ' has a value of ' + data[I][1] + LineEnding;
Memo1.Text := str;
end;
end.