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!5g2000yqz.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Unbounded String to string Date: Tue, 29 Jun 2010 08:19:44 -0700 (PDT) Organization: http://groups.google.com Message-ID: <6137c377-ee81-40af-8d6a-2829ab6dd911@5g2000yqz.googlegroups.com> References: <004d7e0b-cf0a-4a71-ac7e-17b61818b910@5g2000yqz.googlegroups.com> <9eec8378-892b-4299-bde7-4f92535f0c20@x21g2000yqa.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1277824784 4796 127.0.0.1 (29 Jun 2010 15:19:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 29 Jun 2010 15:19:44 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 5g2000yqz.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; .NET4.0C),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:12959 Date: 2010-06-29T08:19:44-07:00 List-Id: On Jun 29, 8:08=A0am, Ludovic Brenta wrote: > 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). Right, when the OP said he wanted to "turn [an unbounded string] into a 16 character subtype", I didn't look more deeply into the words "turn into". I suppose I should have. We'd need to know exactly what his requirements are to provide a full solution, though--- specifically, does he expect any unbounded strings to be shorter than 16 characters, does he expect any of them to be longer than 16 characters, and if either or both is "yes", what it the desired behavior in each case. -- Adam