comp.lang.ada
 help / color / mirror / Atom feed
From: Marc Bejerano <t_mjb@linkabit.titan.com>
Subject: Re: How do I allocate strings of variable length at runtime?
Date: 1997/09/29
Date: 1997-09-29T00:00:00+00:00	[thread overview]
Message-ID: <342FDBDA.67D8427E@linkabit.titan.com> (raw)
In-Reply-To: mheaney-ya023680002609972244450001@news.ni.net


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?
>

<snip>






  reply	other threads:[~1997-09-29  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-26  0:00 How do I allocate strings of variable length at runtime? Oliver Hilgendorf
1997-09-26  0:00 ` William A Whitaker
1997-09-26  0:00 ` Matthew Heaney
1997-09-29  0:00   ` Marc Bejerano [this message]
1997-10-07  0:00     ` Robert I. Eachus
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox