Results 1 to 8 of 8

Thread: Text file into an array

  1. #1
    Join Date
    Feb 2013
    Posts
    89
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default Text file into an array

    how would i append or load a text file that contains a list into an array

    Simba Code:
    TSA := [TextFile];

    TSA := ['item1','item2','item3'];

    Text file:

    item1
    item2
    item3

  2. #2
    Join Date
    Nov 2012
    Posts
    141
    Mentioned
    0 Post(s)
    Quoted
    43 Post(s)

    Default

    I'm unfamiliar with parsing files in PascalScript, but I assuming you want to load settings for your script?
    In that case, you can use this tutorial.

  3. #3
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Simba Code:
    var
      n: Integer;
      str: string;
      TSA: TStringArray;
    begin
      n := OpenFile('C:\Simba\textfile.txt', true);
      ReadFileString(n, str, FileSize(n));
      CloseFile(n);
      // seperates each element in the result TSA by delimeter = ', '
      ExplodeWrap(', ', str, TSA);
    end.

    * Be careful about new lines, I think you might have to box a char value to handle those.

  4. #4
    Join Date
    Feb 2013
    Posts
    89
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    i need to load a wordlist so its kinda confusing for me

  5. #5
    Join Date
    Feb 2013
    Posts
    89
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    Simba Code:
    var
      n: Integer;
      str: string;
      TSA: TStringArray;
    begin
      n := OpenFile('C:\Simba\textfile.txt', true);
      ReadFileString(n, str, FileSize(n));
      CloseFile(n);
      // seperates each element in the result TSA by delimeter = ', '
      ExplodeWrap(', ', str, TSA);
    end.

    * Be careful about new lines, I think you might have to box a char value to handle those.
    Thanks!

  6. #6
    Join Date
    Feb 2013
    Posts
    89
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    how would i handle new lines?

    its just reading them all as one index

  7. #7
    Join Date
    Feb 2013
    Location
    St. Louis
    Posts
    19
    Mentioned
    1 Post(s)
    Quoted
    13 Post(s)

    Default

    Try this for newlines:
    Simba Code:
    ExplodeWrap(#13#10, str, TSA);

  8. #8
    Join Date
    Feb 2013
    Posts
    89
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Sweeet Thanks!!

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
  •