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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,70dee47014cd7083 X-Google-Attributes: gid103376,public From: William A Whitaker Subject: Re: How do I allocate strings of variable length at runtime? Date: 1997/09/26 Message-ID: <342C7830.85D@erols.com>#1/1 X-Deja-AN: 275900963 References: <342bbda6.153101@news.rmi.de> To: Oliver Hilgendorf Organization: Erol's Internet Services X-Received-On: 27 Sep 1997 03:08:05 GMT Reply-To: whitaker@erols.com Newsgroups: comp.lang.ada Date: 1997-09-26T00:00:00+00:00 List-Id: Oliver Hilgendorf wrote: > > I want to open several textfiles using text_io.open. The length of > each filename is only know at runtime. However if I define a string of > the maximum filename-length to hold the filename, all trailing blanks > are also passed to text_io.open and this results in name_error because > a file with trailing blanks does not exist. > So I have to pass a string that is defined with exactly the same > length as the actual filename. > How can I define a string object with variable length at runtime? > > Oliver You can use the function Trim in Ada.Strings.Fixed. (You probably want to extract this function along with what other string handling functionality you use and put them in your own string handling package rather than with the full package every time.) However you obtain your Sloppy_String pass it something like this: Open(Input, In_File, Trim(Sloppy_String, Both); Unfortunately you have to put in the additional parameter, Both means clean up the blanks at both ends (be safe). You would think this function would be defaulted to that, but it is not, although there are several overloads and several defaults. Whitaker