Results 1 to 6 of 6

Thread: String Stuffz

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

    Default String Stuffz

    For all your text manipulation needs:

    SCAR Code:
    program New;

    Var
      A: TStringArray;

    Function Explode(Sep, Text: String): TStringArray;
    Var
      L, Le, I: Integer;
    Begin
      SetArrayLength(Result, 1);
      L := Length(Text);
      For I := 1 To L Do
        If Text[i] <> Sep Then
        Begin
          Le := High(Result);
          Result[Le] := Result[Le] + Text[i];
        End Else
          SetArrayLength(Result, GetArrayLength(Result) + 1);
    End;


    Function AlphabeticalPos(Letter: String): Integer;
    Var
      I: Integer;
      A, L: String;
    Begin
      A := 'abcdefghijklmnopqrstuvwxyz';
      L := LowerCase(Letter);
      For I := 1 To 26 Do // Case would've been boring =]
        If A[i] = L Then
        Begin
          Result := I;
          Exit;
        End;
    End;


    Function OrderToAlphabet(Text: String): TStringArray;
    //* The A's will be found in Result[0] etc.
    Var
      I, L, AP: Integer;
    Begin
      SetArrayLength(Result, 26);
      L := Length(Text);
      For I := 1 To L Do
      Begin
        AP := AlphabeticalPos(Text[i]);
        Result[AP - 1] := Result[AP - 1] + Text[i];
      End;
    End;

     
    Var
      I: Integer;

    begin
      A := OrderToAlphabet('ababcdcd');
      For I := 0 To High(A) Do
        Writeln(A[i]);

    end.

    EDIT: Explode isn't originally my idea ofcourse, I just wanted to try to do it that way

  2. #2
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Bubble. Sorting. Is. Slow. As. Hell.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  3. #3
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    what does explode exactly do?

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

    Default

    SCAR Code:
    program New;

    Var
      A: String;
      B: TStringArray;

    Function Explode(Sep, Text: String): TStringArray;
    Var
      L, Le, I: Integer;
    Begin
      SetArrayLength(Result, 1);
      L := Length(Text);
      For I := 1 To L Do
        If Text[i] <> Sep Then
        Begin
          Le := High(Result);
          Result[Le] := Result[Le] + Text[i];
        End Else
          SetArrayLength(Result, GetArrayLength(Result) + 1);
    End;
    var i:integer;
    begin
      A := 'hello/nice/to/meet/you';
      B := Explode('/',A);
      for i:=0 to 4 do
        writeln(B[i]);
    end.


    Successfully compiled
    hello
    nice
    to
    meet
    you
    Successfully executed

  5. #5
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    SRL/Misc/arrayloader.scar




    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

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

    Default

    Sweet, but tell me, in what occasion I would have to turn string to tpointarray instead of intz?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 5
    Last Post: 03-30-2008, 01:40 PM

Posting Permissions

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