I am making a DTM database (don't ask how) and I will have a search function. Here is my functions. They may seem weird on how they do it, but it's creative, but I want it shortened. Basically it is supposed to do this:
1. You are trying to find all the instances of a block of text in a string array. It will return the array index of all found instances in the result array for future use.
2. The analyzetext function is a bit weird but it does this; it looks for the text in the specified string. Then if it's found it returns true.
3. The Search procedure searchs for the text in the entire array using analyzetext for each individual string.
That's how it works.
Don't criticize it by saying why did you do it that way or anything because I was a good scripter but I stopped for a while and forgot most of the functions so I was improvising and trying to find how to do this but couldn't find out how. If someone has found a way please tell me.
SCAR Code:
function AnalyzeText(FindText : string; VarText : string) : boolean;
var
i : integer;
TempStr : string;
begin
TempStr := VarText;
begin
TempStr := Replace(TempStr, FindText, '楕');
TempStr := Between('æ', '•', TempStr);
if TempStr = '¥' then Result := true;
exit;
end;
end;
function Search(SearchText : string; SearchArray : array of string) : array of integer;
var
i : integer;
ArrAt : integer;
begin
for i := 0 to GetArrayLength(SearchArray) - 1 do
begin
if AnalyzeText(SearchText, SearchArray[i]) then
begin
setarraylength(result, getarraylength(result) + 1);
Result[ArrAt] := i;
inc(ArrAt);
end;
end;
end;
All I want is a function that will do that, but make the function shorter.
Thanks.