SRL Archive - OSR Help

Can someone explain how to use SplitRegExpr and TStrings?


EGM

2010-11-03 16:01:26

I've looked through the tutorials, the examples, and whatever else I could find and I can't find any explanation how to use SplitRegExpr, beyond it choking when I pass it a TStrings variable, and it crashing when I don't…

Any (working) examples someone can pass to me for SplitRegExpr?

Dgby714

2010-11-03 16:24:55

You can use this function =)

TStrings are only abstract atm so you need to use TStringList

program new;

function SplitRegExprEx(Expr, Data: string): TStringArray;
var
DataArr: TStringList;
I: integer;
begin
DataArr := TStringList.Create;
try
SplitRegExpr(Expr, Data, DataArr);
SetArrayLength(Result, DataArr.Count);
for I := 0 to DataArr.Count - 1 do
Result[I] := DataArr.Strings[I];
finally
DataArr.Free;
end;
end;

var
S: TStringArray;

begin
S := SplitRegExprEx('[e|s|i]', 'Testing this little string');
WriteLn('S := ' + ToStr(S) + ';');
end.

[offtopic]Woo I'm not a chicken anymore =P[/offtopic]