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,db8ef2e54cb04ab9 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!b35g2000yqi.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Unbounded String to string Date: Tue, 29 Jun 2010 08:08:45 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <004d7e0b-cf0a-4a71-ac7e-17b61818b910@5g2000yqz.googlegroups.com> <9eec8378-892b-4299-bde7-4f92535f0c20@x21g2000yqa.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1277824125 29950 127.0.0.1 (29 Jun 2010 15:08:45 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 29 Jun 2010 15:08:45 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: b35g2000yqi.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:12958 Date: 2010-06-29T08:08:45-07:00 List-Id: tonyg wrote on comp.lang.ada: > On 29 June, 15:33, Adam Beneschan wrote: >> On Jun 29, 7:28=A0am, tonyg wrote: > >>> Hi, >>> =A0 =A0I have an unbounded string from a database I want to turn into a= 16 >>> character subtype of string >>> >>> i.e. unbounded_string to string(1..16) >>> >>> I've been trying to do this most of the afternoon but keep getting >>> errors >>> >>> anyone know how ? > >> Declare a subtype to give string(1..16) a name; then call To_String >> (in Ada.Strings.Unbounded) and convert the function result to your >> subtype. =A0E.g.: >> >> =A0 =A0subtype String_Length_16 is string(1..16); >> =A0 =A0V : String_Length_16; >> >> =A0 =A0V :=3D String_Length_16 (Ada.Strings.Unbounded.To_String (U)); That solution only works if U happens to contain exactly 16 characters, which is probably not the case if the database really contains unbounded strings (i.e. VARCHAR or similar). So what you probably need is something more elaborate along the lines of: function To_String_16 (U : Ada.Strings.Unbounded.Unbounded_String) return String_16 is Temp : constant String :=3D Ada.Strings.Unbounded.To_String (U); Result : String_16; begin Ada.Strings.Fixed.Move (Source =3D> Temp, Target =3D> Result, Drop =3D> Ada.Strings.Right, Justify =3D> Ada.Strings.Left, Pad =3D> Ada.Characters.Space); return Result; end To_String_16; (some parameters of Ada.Strings.Fixed.Move have defaults; I spelled all them out for clarity at the expense of conciseness). -- Ludovic Brenta.