Results 1 to 6 of 6

Thread: Function StrToArray

  1. #1
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default Function StrToArray

    After playing with php and scar a bit more, I realised that (esecially) when using databases to create pages for scar to then interpret, it became pretty hard to be able to get those values into scar, thus StrToArray was made.

    SCAR Code:
    Function StrToArray(Var stra: array of String; str,del: String): Boolean;
    Var
      sx,i: Integer;

    Begin
      If(Not(Right(str,Length(del)) = del)) Then
        str:= str+del;
      Repeat
        Begin
          sx:= Pos(del,str);
          SetArrayLength(stra,GetArrayLength(stra)+1);
          stra[i]:= Copy(str,1,sx-1);
          Delete(str,1,sx+(Length(del)-1));
          i:=i+1;
        End
      Until(str = '')
      Result:=True;
    End;
    It works by finding where the first delmiter is and copying from the start until it gets to the delimiter and puts it into the array. It then deletes the part it has copied and the delimiter before looping again until the string (str) is empty. It makes the array's length 1 larger everytime it loops so there's no out of range errors.

    You would then use it as
    SCAR Code:
    StrToArray(stringArray,String,Delimiter);
    or
    SCAR Code:
    StrToArray(Scripts,'hello. moo. carrot','. ');

    With (in the 1st) stringArray being the array it puts all the values in, String being the string it takes the text from before converting it and Delimiter being the characters that separate each different piece of text (normally ', ' or ',').

    In the 2nd case, it would assign 'hello' to stringArray[0], 'moo' to stringArray[1] and 'carrot' to stringArray[2].

    Feel free to post improvements/questions or anything else.

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Nice peice. Might use soon
    GJ!!!

  3. #3
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Dude...you should try makeing runescape script and apply for members

    Nice one btw
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  4. #4
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I would make a runscape script, but it's just too much work (well, for me atleast, as I am a perfectionist when it comes to most of my scripting). Anyway, currently just working on a few bits and bobs and this was core to being able to get a list of text out of the database and into an array (which is mainly what I'm playing with) and it seemed like it could be useful to a few people.

  5. #5
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Nice =]

    Have you also looked at TStringListExample2 from SCAR? It's in your scripts/Test/ folder.

    SCAR Code:
    program TStringListExample2;
    var
      strlist: TStringList;
      i: Integer;
     
    procedure Split(Text: string; Delimiter: Char; var Dest: TStringList);
    begin
      Dest.Clear;
      Dest.DelimitedText := Text;
      Dest.Delimiter := Delimiter;
    end;
     
    begin
      strlist := TStringList.Create;
      Split('45d8,578,4,726,keo', ',', strlist);
      for i := 0 to strlist.Count - 1 do
        WriteLn(strlist.Strings[i]);
      strlist.Free;
    end.

    Not a TStringArray, but still might be usefull
    Hup Holland Hup!

  6. #6
    Join Date
    Aug 2007
    Posts
    1,404
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    It seems like a good start to know how SCAR works with things. The more perfectionist you are with your scripts, the better they will be. You should really try it.

    -Knives

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with a function.
    By Floor66 in forum OSR Help
    Replies: 15
    Last Post: 04-15-2008, 02:03 PM
  2. Replies: 2
    Last Post: 02-27-2008, 05:20 PM
  3. Replies: 2
    Last Post: 02-26-2008, 08:26 PM
  4. [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]
    By ZephyrsFury in forum Research & Development Lounge
    Replies: 10
    Last Post: 07-27-2007, 08:45 AM

Posting Permissions

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