aran armath
05-11-2010, 02:00 AM
I want to get scar to read each line from a .txt file one by one and insert into the script. Any way to do this?
Yes just read the file and explode it based on the new line/carriage return characters.
aran armath
05-11-2010, 02:09 AM
Yes just read the file and explode it based on the new line/carriage return characters.
Huh?
Baked0420
05-11-2010, 02:36 AM
nuke it... lol
what he means is read the file and explode it with:
function Explode(Separator, s: String): TStringArray;
The string would be the file, the separator would be the return key, it would be char(13) I think, but not sure, I would doulbe check. And I never used explode, but I'm guessing that Sex is telling you to use the return character as the separator, since the whole string would be the file, then you have your file exploded by lines all returned in an array of strings.
EDIT: I never read a file before but I have seen it done looking at source code around SRL before, but I forgot sorry, but you just need to find that and then use it with explode to get what you want. If I find how to read files I'll let you know.
EDIT2: control+space shows ReadFileString, and in a thread from 2008 Timer asks about saving a file, in there XcanadamanX shows reading a file. (http://villavu.com/forum/showpost.php?p=303883&postcount=2)
Basically what you want to do for reading a file (based of XcanadamanX's example) is:
const
FileName = ''; //exact location of file
var
file: longint;
s: String;
begin
file:= OpenFile(FileName, false);
ReadFileString(file, s, FileSize(file));
CloseFile(file);
writeln(s);
end.
(Above not yet tested)
EDIT3: Tested with a .txt file on my desktop, works, just put in your file name (Ex: mine was 'C:\Users\James\Desktop\JavaConversion.txt'
EDIT4: Exploding with return key:
program FileReading;
const
FileName = ''; //exact location of file
var
i: integer;
file: longint;
s: String;
s2: TStringArray;
begin
file:= OpenFile(FileName, false);
ReadFileString(file, s, FileSize(file));
CloseFile(file);
//writeln(s); //writes the file
S2:= Explode(Chr(13), s);
for i:= low(S2) to high(S2) do
writeln(S2[i]); //writes each index of the String Array, each index is up to the return key (or should be)
end.
Try to look at what I did so you learn, sorry I kinda did it for you, it's the best way I can show you what to do, I tried explaining it the best I can, if you have any questions on what I did just ask and I'll try to explain it better.
mastaraymond
05-11-2010, 09:38 AM
program new;
var
x : TStringList;
i : integer;
begin
x := TStringList.Create;
x.LoadFromFile('c:\mytestfile');
for i := 0 to x.count - 1 do
writeln(x[i]);
x.free;
end.
Probably only works in Simba :<
Baked0420
05-11-2010, 04:41 PM
Only reason it doesn't work in SCAR is because there is no TStringList.LoadFromFile(s: String);
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.