SRL Archive - OSR Help

Searching a file/string


xdarkshadowx

2012-05-06 23:26:13

I need to search in a file that i'm putting into a string, I've read the file into a string but I've heard that my string can only hold 255 characters from the file. so I'll need to get around that, and I'll need to search for things and get their position that repeat multiple times. and then to search from a specific point would be nice. I know of pos(substring,string); but that only returns the first result…

Main

2012-05-06 23:37:19

unfortunately you can only achieve something like that if your file are formatted in simba/pascal's standards.

You can check out:
http://docs.villavu.com/simba/scriptref/files.html

xdarkshadowx

2012-05-07 02:06:34

yeah those haven't been super helpful.. :s

Janilabo

2012-05-07 02:42:01

2 functions from MSSL, that you might find useful:

PosAll
function PosAll(s, str: string): TIntegerArray;
var
sL, strL, o, p, r: Integer;
begin
sL := Length(s);
strL := Length(str);
if sL > strL then
Exit;
SetLength(Result, strL);
repeat
p := PosEx(s, str, (o + 1));
if p > 0 then
begin
Result[r] := p;
o := p;
Inc(r);
end;
until p <= 0;
SetLength(Result, r);
end;

PosAll SHORTER edition
function PosAll(s, str: string): TIntegerArray;
var
strL, p, r: Integer;
begin
strL := Length(str);
if Length(s) > strL then
Exit;
SetLength(Result, strL);
repeat
p := PosEx(s, str, (p + 1));
if p > 0 then
Result[r] := p;
Inc(r);
until p <= 0;
SetLength(Result, (r - 1));
end;

Count
function Count(s, str: string): Integer;
var
p: Integer;
begin
if Length(s) <= Length(str) then
repeat
p := PosEx(s, str, (p + 1));
if p > 0 then
Inc(Result);
until p <= 0;
end;

Count2 (Method 2… Seems to work faster than Method 1.)
function Count2(s, str: string): Integer;
var
i, sL, strL: Integer;
begin
sL:= Length(s);
strL := Length(str);
if sL > strL then
Exit;
for i := 1 to ((strL - sL) + 1) do
if Copy(str, i, sL) = s then
Inc(Result);
end;