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: Marc Bejerano Subject: Re: How do I allocate strings of variable length at runtime? Date: 1997/09/29 Message-ID: <342FDBDA.67D8427E@linkabit.titan.com>#1/1 X-Deja-AN: 276477651 References: <342bbda6.153101@news.rmi.de> Organization: Titan Linkabit Newsgroups: comp.lang.ada Date: 1997-09-29T00:00:00+00:00 List-Id: Just use Ada.Strings.Unbounded and when you need to call Text_IO.Open simply pass it the To_String version of your variable. For example: with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO; use Ada.Text_IO; ... fileName: Unbounded_String; inputFile: File_Type; fileName := To_Unbounded_String ("whatever.data"); Open (inputFile, In_File, To_String (fileName); This will solve your dilemma regarding the blanks at he end of the string. Alternatively, you could use the Ada.Strings.Maps package and physically Trim(...) the string prior to passing it to the Open call. -Marc P.S. Remember, keep it simple. Matthew Heaney wrote: > In article <342bbda6.153101@news.rmi.de>, hilgend@rmi.de (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? > > You need to specify more information: What is the source of filenames? Do > you have to store the filenames prior to opening the files? >