Results 1 to 5 of 5

Thread: Explode Help

  1. #1
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default Explode Help

    For some reason, this does not return every word in the string

    SCAR Code:
    program new;
    begin
    var m,b:string;
    tsb : tstringarray;
    i:integer;
    begin
    setupsrl;
    //m := GetTheText;
    m := 'omfg dude this is sick';
    setarraylength(tsb, 9);
    tsb := explode(' ', m);
    writeln(''+inttostr(length(tsb))+'');
    writeln('ex1:'+tsb[0]+'');
    writeln('ex2:'+tsb[1]+'');
    writeln('ex1:'+tsb[3]+'');
    writeln('ex2:'+tsb[4]+'');

    for i := 0 to high(ts) do
    begin
      writeln('EX:'+tsb[i]);
    end;
    end.

    Dont comment on the standards please, and also, how come my for to do loop wont work?

  2. #2
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Um, it does work?

  3. #3
    Join Date
    May 2007
    Location
    Ohio
    Posts
    2,296
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR Code:
    var
      m: String;
      tsb: TStringArray;
      i: Integer;
     
    begin
      m := 'omfg dude this is sick';
      SetArrayLength(tsb, 9);
      tsb := Explode(' ', m);
      WriteLn(inttostr(length(tsb)));
      WriteLn('ex1:' + tsb[0]+'');
      WriteLn('ex2:' + tsb[1]+'');
      WriteLn('ex1:' + tsb[3]+'');
      WriteLn('ex2:' + tsb[4]+'');

      for i := 0 to High(tsb) do
      begin
        WriteLn('EX:'+tsb[i]);
      end;
    end.

    your loop is High of ts, not tsb.
    You never use b.
    Code:
    Successfully compiled (45 ms)
    5
    ex1:omfg
    ex2:dude
    ex1:is
    ex2:sick
    EX:omfg
    EX:dude
    EX:this
    EX:is
    EX:sick
    Successfully executed
    Returned it all for me (that you told it too).
    Add WriteLn('ex?:' + tsb[2]+''); you get. <- You forgot [2]
    Code:
    Successfully compiled (45 ms)
    5
    ex1:omfg
    ex2:dude
    ex?:this
    ex1:is
    ex2:sick
    EX:omfg
    EX:dude
    EX:this
    EX:is
    EX:sick
    Successfully executed
    SCAR Code:
    var
      m: String;
      tsb: TStringArray;
      i: Integer;
     
    begin
      m := 'omfg dude this is sick';
      SetArrayLength(tsb, 9);
      tsb := Explode(' ', m);
      WriteLn(inttostr(Length(tsb)));
      WriteLn('ex1:' + tsb[0]);
      WriteLn('ex2:' + tsb[1]);
      WriteLn('ex?:' + tsb[2]);
      WriteLn('ex1:' + tsb[3]);
      WriteLn('ex2:' + tsb[4]);

      for i := 0 to High(tsb) do
      begin
        WriteLn('EX:'+tsb[i]);
      end;
    end.

  4. #4
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Timer View Post
    SCAR Code:
    var
      m: String;
      tsb: TStringArray;
      i: Integer;
     
    begin
      m := 'omfg dude this is sick';
      SetArrayLength(tsb, 9);
      tsb := Explode(' ', m);
      WriteLn(inttostr(length(tsb)));
      WriteLn('ex1:' + tsb[0]+'');
      WriteLn('ex2:' + tsb[1]+'');
      WriteLn('ex1:' + tsb[3]+'');
      WriteLn('ex2:' + tsb[4]+'');

      for i := 0 to High(tsb) do
      begin
        WriteLn('EX:'+tsb[i]);
      end;
    end.

    your loop is High of ts, not tsb.
    You never use b.
    Code:
    Successfully compiled (45 ms)
    5
    ex1:omfg
    ex2:dude
    ex1:is
    ex2:sick
    EX:omfg
    EX:dude
    EX:this
    EX:is
    EX:sick
    Successfully executed
    Returned it all for me (that you told it too).
    Add WriteLn('ex?:' + tsb[2]+''); you get. <- You forgot [2]
    Code:
    Successfully compiled (45 ms)
    5
    ex1:omfg
    ex2:dude
    ex?:this
    ex1:is
    ex2:sick
    EX:omfg
    EX:dude
    EX:this
    EX:is
    EX:sick
    Successfully executed
    SCAR Code:
    var
      m: String;
      tsb: TStringArray;
      i: Integer;
     
    begin
      m := 'omfg dude this is sick';
      SetArrayLength(tsb, 9);
      tsb := Explode(' ', m);
      WriteLn(inttostr(Length(tsb)));
      WriteLn('ex1:' + tsb[0]);
      WriteLn('ex2:' + tsb[1]);
      WriteLn('ex?:' + tsb[2]);
      WriteLn('ex1:' + tsb[3]);
      WriteLn('ex2:' + tsb[4]);

      for i := 0 to High(tsb) do
      begin
        WriteLn('EX:'+tsb[i]);
      end;
    end.
    wow thanks

  5. #5
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    var
      s :string;
      TSA : TStringArray;
      i, h :integer;

    begin
      s := 'omfg dude this is sick';
      TSA := explode(' ', s);
      Writeln(IntToStr((GetArrayLength(TSA))));
      h := high(TSA);
     for i := 0 to h do
       Writeln('ex' + IntToStr(i + 1) + ': '+ TSA[i]);
    end.
    Last edited by Sex; 01-08-2010 at 09:01 PM. Reason: Standards, sorry ;D
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

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
  •