Results 1 to 10 of 10

Thread: Explode

  1. #1
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Explode

    Sorry if you feel cheated, but no explosions in this thread. Aww what the hell. Have one. http://sightsonics.cf.huffingtonpost...-explosion.jpg

    Anyway, that stupidity out of the way

    I got bored and made a function, explode. If you've ever used PHP, Perl, or the Java equivalent, Split(), then you know what it is. If not, it takes a string and splits it into an array, based on a common delimiter.

    ex: "Cheese+Is+Tasty" Would become Arr[0] := 'Cheese', Arr[1] := 'Is' Arr[3] := 'Tasty'

    To be honest, I can't even think where it would be useful, but...what the hay. I made it anyway. Here it is:

    SCAR Code:
    program Explosion;

    //Ohai
    //Why did I make this? I dunno. I got bored.

    var
      TestArr : TStringArray;
      i2 : integer;

    function Explode(Delimiter : string; Str : string) : array of string;
    var
      DelimPos, i : integer;
      Arr1 : array of string;
    begin
      SetArrayLength(Arr1, 100000);
      i := 0;
      repeat
        if (pos(Delimiter, Str) = 0) then Break;
        DelimPos := pos(Delimiter, Str);
        Arr1[i] := Replace((copy(Str,0,DelimPos)),Delimiter,'');
        Delete(Str,1,DelimPos);
        i := i + 1;
      until(pos(Delimiter, Str) = 0);
      Arr1[i] := Str;
      SetArrayLength(Arr1, i+1);
      Result := Arr1;
    end;



    //Do whatever you want with it.
    begin
      TestArr := Explode('-','Runescape-Is-Fun-But-Pking-Sucks');
      i2 := 0;
      repeat
        Writeln('Array['+IntToStr(i2)+'] = '+TestArr[i2]);
        i2 := i2 + 1;
      until(i2 = GetArrayLength(TestArr));
    end.

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

    Default

    I might use this to store autoing talking sentences.

  3. #3
    Join Date
    Oct 2006
    Location
    I'm also from Michigan!
    Posts
    563
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    nice! explode is one of my favorite PHP functions but i never really saw a use for it on SCAR. looks real good though.

  4. #4
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks for the nice feedback guys

  5. #5
    Join Date
    Sep 2006
    Posts
    5,219
    Mentioned
    4 Post(s)
    Quoted
    1 Post(s)

    Default

    About a year ago I had a port phasmatys smelter that used 2 SCARs with ISM, and it would send lots of info in 1 string, and then separate with explode. Quite useful.

  6. #6
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    SCAR Code:
    procedure Split(Text: string; Delimiter: Char; var Dest: TStringList);
    begin
      Dest.Clear;
      Dest.DelimitedText := Text;
      Dest.Delimiter := Delimiter;
    end;

    Test folder of the scar directory

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


  7. #7
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Bob whats the difference between TStringArray and TStringList except for that StringList is a record type?

  8. #8
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    PM Freddy. I have no idea


  9. #9
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    TStringArray is an array, TStringList has manipulation functions and stuff like that (add, remove, loadfromfile etc).
    I made a new script, check it out!.

  10. #10
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Oh, okay, thanks markus.

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
  •