SRL Archive - OSR Help

Text file into an array


xxpoopyxx

2013-03-15 15:01:07

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


TSA := [TextFile];

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

Text file:

item1
item2
item3

Neodymium

2013-03-15 15:07:55

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.

Le Jingle

2013-03-15 15:11:13


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.

xxpoopyxx

2013-03-15 15:12:22

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

xxpoopyxx

2013-03-15 15:13:22

From: Le Jingle

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!

xxpoopyxx

2013-03-15 15:26:11

how would i handle new lines?

its just reading them all as one index :(

microsphere

2013-03-15 15:31:07

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

xxpoopyxx

2013-03-15 15:33:27

Sweeet Thanks!!