From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,a3fe2aac201210c0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local1.nntp.dca.giganews.com!nntp.comcast.com!news.comcast.com.POSTED!not-for-mail NNTP-Posting-Date: Fri, 16 Jul 2004 21:27:03 -0500 Date: Fri, 16 Jul 2004 22:27:03 -0400 From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: reading a text file into a string References: <40f6bf21@dnews.tpgi.com.au> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Message-ID: NNTP-Posting-Host: 24.147.90.114 X-Trace: sv3-S7ELOTsg+ztqjZpVXISeAxarGjw125pLF6YiHmqKjmZx7SBJjesVbfIyLkLOXQCCp21n8PUa1/S4BUZ!YEmOSaFIhtzf/MmRlgakBf6Tpw45NuEneOgN+zBTEm7xwmucdrwOGscv+jbaCg== X-Complaints-To: abuse@comcast.net X-DMCA-Complaints-To: dmca@comcast.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.1 Xref: g2news1.google.com comp.lang.ada:2204 Date: 2004-07-16T22:27:03-04:00 List-Id: There have been a lot of useful tips in this thread on how to accomplish the stated goal. But what is really missing is a discussion of HOW a newbie should decide what he actually wants to do. What you have to do is refine your requirements, and that can be the most important, and most time consuming step when programming in Ada. I usually state it as Ada is much better at doing what you tell it to do than other languages. But it is like a four-year old child, always asking, "Why?" So before you decide whether to represent line-breaks with nulls, linefeeds, or copy the existing characters exactly, you have to know the answer to the "Why?" question. In this case, "Why are you reading the file?" Once you know whether you need a bitwise copy of the file, to parse the text and reformat it, or merely to scan through the contents of the file, then you can decide the right way to read the file. I usually find that when I have though about it enough, I want to do line at a time processing, rather than character at a time, or reading the entire file in one gulp. For this reason, I find myself contructing or using a Get_Line FUNCTION inside a loop and a declare block: while not End_of_Line(Somefile) loop declare Buffer: String := Get_Line(Somefile); begin -- process buffer exception ... end; end loop; Each iteration of the loop, the Buffer contains a CONSTANT String, but it is potentially different in length and content every time through. Incidently, GNAT has a special package to allow you to do a Get_Line into an Unbounded_String, no matter how long. I think I posted a "clever example" of how to do it here, and if you need it I can find it again. (The code is an elegant example of the use of recursion. Using the GNAT equivalent is better performance-wise if you really are reading multi-megabyte lines.) -- Robert I. Eachus "The flames kindled on the Fourth of July, 1776, have spread over too much of the globe to be extinguished by the feeble engines of despotism; on the contrary, they will consume these engines and all who work them." -- Thomas Jefferson, 1821