Results 1 to 4 of 4

Thread: Searching a file/string

  1. #1
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default Searching a file/string

    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...

  2. #2
    Join Date
    Sep 2007
    Location
    British Columbia, Canada
    Posts
    4,047
    Mentioned
    1 Post(s)
    Quoted
    2 Post(s)

    Default

    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
    Oh Hai Dar

  3. #3
    Join Date
    Feb 2012
    Posts
    170
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

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

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    2 functions from MSSL, that you might find useful:

    PosAll
    Simba Code:
    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
    Simba Code:
    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
    Simba Code:
    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.)
    Simba Code:
    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;
    Last edited by Janilabo; 05-08-2012 at 02:41 PM.

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
  •