Results 1 to 6 of 6

Thread: How To Read The Exact Text From A File?

  1. #1
    Join Date
    Sep 2007
    Location
    Bikini Bottom
    Posts
    50
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default How To Read The Exact Text From A File?

    I'm currently busy working on a script, and I made my own save-something-to-file-function:
    Code:
    procedure SaveLineToFile(filenumber:Integer; line:String);
    var
    oldcontent:String;
    newcontent:String;
    begin
         ReadFileString(filenumber, oldcontent, filesize(filenumber));
         newcontent:=oldcontent+chr(13)+line;
         WriteFileString(filenumber, newcontent);
    end;
    The problem is that I want ReadFileString to put the entire content of the file in the string "oldcontent", but he also takes a lot of bytes behind the last letter...
    That means, when I write things to the file using this function, between the first and the last are a lot of strange marks, words like "TMenu" or something, and a lot of Carriage Returns (in NotePad shown as a square)....

    So, how to get the exact length of the text inside the file, so I can read it properly? filesize(filenumber) apparantly gives more than the actual content, thus ruining my file...

  2. #2
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    I don't know a lot about this; but try reading the Scar Manual. It has some read and write functions in it. Might have what you are looking for.

    Nava2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    ReadInI and WriteInI

    That should work

  4. #4
    Join Date
    May 2006
    Location
    Amsterdam
    Posts
    3,620
    Mentioned
    5 Post(s)
    Quoted
    0 Post(s)

    Default

    Eh? You sure? Because for me it works allright..

    SCAR Code:
    program Hoi;
    var
      filenum : integer;
      str : String;
    begin
      fileNum := RewriteFile(apppath + 'test.txt',true);
      WriteFileString(FileNum,'TESSTTTTTT AAAH ' + chr(13) + 'Testz0r');
      CloseFile(Filenum);
      filenum := OpenFile(apppath + 'test.txt',true);
      ReadFileString(Filenum,str, FileSize(filenum));
      Writeln(str + '- END HERE');
      CloseFile(FileNum);
    end.
    Verrekte Koekwous

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

    Default

    For returns, use chr(13)+chr(10) instead of chr(13) That will make them work with notepad.
    I made a new script, check it out!.

  6. #6
    Join Date
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    For returns, use chr(13)+chr(10) instead of chr(13) That will make them work with notepad.
    Since you're a dev, you kinda scare me.. it's like you know everything now

    -Tsn.
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Adding text to a file...
    By Drakan in forum OSR Help
    Replies: 3
    Last Post: 05-11-2009, 11:21 AM
  2. Replies: 4
    Last Post: 10-11-2008, 03:48 AM
  3. Writing to a text file
    By JNCR in forum OSR Help
    Replies: 2
    Last Post: 10-20-2007, 02:33 PM
  4. Getting Text File from Web?
    By MacroHawk in forum OSR Help
    Replies: 3
    Last Post: 05-12-2007, 03:36 AM

Posting Permissions

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