Results 1 to 3 of 3

Thread: Please shorten this...

  1. #1
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Please shorten this...

    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.

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function Search(SearchText : string; SearchArray : array of string) : array of integer;
    var
      i : integer;
    begin
      for i := 0 to High(SearchArray) do
        if(Pos(SearchArray[i], SearchText) > 0)then
        begin
          SetLength(Result, Length(Result) + 1);
          Result[High(Result)]:= I;
        end;
    end;

  3. #3
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Edit: nevermind it works. Error on my part .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •