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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7bf23c8e794b6462 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Newsgroups: comp.lang.ada Subject: Re: STRING length From: Georg Bauhaus In-Reply-To: <1163544675.070347.64490@h54g2000cwb.googlegroups.com> References: <1163544675.070347.64490@h54g2000cwb.googlegroups.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: # Message-ID: <1163543045.5361.12.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Date: Tue, 14 Nov 2006 23:24:05 +0100 NNTP-Posting-Date: 15 Nov 2006 00:21:24 CET NNTP-Posting-Host: c7564eae.newsspool3.arcor-online.net X-Trace: DXC=\RYO4[HYN4>85[]]\]T081McF=Q^Z^V384Fo<]lROoR1gUcjd<3m<;2^@^?JcUT=d9PCY\c7>ejV84LKcb4f=4O4eC<9S:Lm\<3 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:7455 Date: 2006-11-15T00:21:24+01:00 List-Id: On Tue, 2006-11-14 at 14:51 -0800, markww wrote: > Hi, > > How does one use a variable length string in ada? You use variable length strings in Ada by declaring them to be of type UNBOUNDED_STRING which is defined in Ada.Strings.Unbounded. type MY_RECORD is record Name: UNBOUNDED_STRING; Phone: UNBOUNDED_STRING; Address: UNBOUNDED_STRING; end record; Given that Phone is likely to be limited in length, you could consider declaring the Phone component to be of type BOUNDED_STRING, which is a string type with a maximum length. Unlike STRING, objects of this type can have any number of characters up to the maximum. See Ada.Strings.Bounded. Yet another use of strings is in nested scopes: If you need a string in just one place, e.g. temporarily, you can use a plain STRING as in declare temp: constant STRING := some_string_returning_func(...); begin -- use temp end; The point here is that the `temp` string variable takes its bound from the initialization. You can also make it a variable, if you need to write to string components. See http://en.wikibooks.org/wiki/Ada_Programming/Strings -- Georg