kazhual
2012-10-28 17:23:14
Hello,
I was looking for a function which could search within a String, but i havent found anything so here is my solution for in case you are interested.
Example:
text1 := 'the bank is closed in 5 min';
text2 := 'bank';
SearchString(text1, text2);
this function will search for 'bank' in text1 and returns True of found.
I Hope you like it
I was looking for a function which could search within a String, but i havent found anything so here is my solution for in case you are interested.
Example:
text1 := 'the bank is closed in 5 min';
text2 := 'bank';
SearchString(text1, text2);
this function will search for 'bank' in text1 and returns True of found.
I Hope you like it
program Development;
{$DEFINE SMART}
{$i srl/srl.simba}
function SearchString(s1,s2: string): Boolean;
var
i, j, k: Integer;
begin
Result := false;
for i:= 1 to ( length(s1)-length(s2)+1 ) do begin
if ( s1[i] = s2[1] ) then begin
dec(i);
for j:= 1 to length(s2) do begin
if ( s1[i+j] = s2[j] ) then begin
inc(k);
end;
if ( k = length(s2) ) then begin
Result := True;
end;
end;
inc(i);
end;
end;
end;
var
text1 : string;
text2 : string;
begin
text1 := 'the bank is closed in 5 min';
text2 := 'bank';
SearchString(text1, text2);
WriteLn( BoolToStr( SearchString(text1, text2) ) );
end.