Results 1 to 4 of 4

Thread: String components?

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default String components?

    I was wondering if anyone knows the way to break down a single string into individual components? I've been looking around and I can't seem to find anything of use. Although I did stumble across the 'TStringList' type, although I'm not completely sure where it's used and what it's used for.

    What would really be wonderful is a function to extract all the string characters from a single string and output a TStringArray containing each character. Also a function to do just the opposite.

    An example would be:
    Simba Code:
    Procedure FunWithStrings;
      var
        Text,NewStr: String;
        StrComps: TStringArray;
      begin
        Text := 'Hey';
        StrComps := ExtractString(Text);    //This would return  ['H', 'e', 'y']
        NewStr := CompressStrAr(StrComps);  //This would return 'Hey'
      end;

    Sometimes it's easier to explain something through code.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


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

    Default

    I take it you have a very good reason for not accessing it @ char level (a string is an array, too!), but here you go:
    Simba Code:
    function ExtractString(str : string) : TstringArray;
    var i : integer;
    begin
      SetLength(result, length(str));
      for i := 1 to high(str) do
        result[i-1] := str[i];
    end;

    function CompressStrAr(StrComps : TStringArray) : string;
    var i : integer;
    begin
      result := '';
      for i := 0 to high(StrComps) do
        result := result + StrComps[i];
    end;
    Untested, uncompiled.
    I made a new script, check it out!.

  3. #3
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Perfecto'. Yeah I'm playing around with alternative RS text-finding. Thanks Markus.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  4. #4
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Simba Code:
    Procedure FunWithStrings;
      var
        Text: String;
      begin
        Text := 'Hey';
        Writeln(Text[1]);
        Writeln(Text[2]);
        Writeln(Text[3]);
      end;

    I don't understand why just don't use this.
    Working on: Tithe Farmer

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
  •