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=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.224.122.15 with SMTP id j15mr2560327qar.6.1413998205329; Wed, 22 Oct 2014 10:16:45 -0700 (PDT) X-Received: by 10.140.87.71 with SMTP id q65mr16789qgd.39.1413998205313; Wed, 22 Oct 2014 10:16:45 -0700 (PDT) Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!cm18no359934qab.0!news-out.google.com!u5ni12qab.1!nntp.google.com!cm18no359929qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 22 Oct 2014 10:16:45 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=71.229.110.218; posting-account=wEPvUgoAAABrLeiz_LRhQ3jeEhyfWVMH NNTP-Posting-Host: 71.229.110.218 References: <7c1b89e6-9ab8-4faa-b60c-c5c4683f0bff@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <2a530b7a-cc6a-4a47-a7b4-51608d785508@googlegroups.com> Subject: Re: Assembling Complex Strings Containing Carriage Returns Prior to Using Ada.Text_IO.Put? From: NiGHTS Injection-Date: Wed, 22 Oct 2014 17:16:45 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: number.nntp.giganews.com comp.lang.ada:189974 Date: 2014-10-22T10:16:45-07:00 List-Id: On Wednesday, October 22, 2014 2:20:35 AM UTC-4, mockturtle wrote: > On Wednesday, October 22, 2014 7:57:39 AM UTC+2, NiGHTS wrote: > > > I am converting some code from C to Ada which involves building a complex string containing '\n' characters which would eventually be displayed on the standard output console using the printf() function. > > > > > > > > > > > > I tried to copy the same strategy of building the string in Ada like this: > > > > > > > > > > > > > > > > > > Complex_String : Ada.Strings.Unbounded.Unbounded_String; > > > > > > EOL : String := ASCII.CR'Img; > > > > > > > > > > > > ... > > > > > > > > > > > > Ada.Strings.Unbounded.Append (Complex_String, > > > > > > "Menu Title" & EOL & > > > > > > "-------------------------------------" & EOL > > > > > > ); > > > > > > > > > > > > ... > > > > > > > > > > > > Ada.Text_Io.Put ( > > > > > > Ada.Strings.Unbounded.To_String( Complex_String ) ); > > > > > > Instead of breaking the line in the places where EOL has been inserted, it seems to show the letters "CR" in its place. > > > > > > The searches I performed on Google seem to be void of any hints on how to get this working. I can't imagine that I am the only one with this requirement in Ada. > > > > > > Thanks in advance for your advice. > > > > Do not use 'Img (that, by the way, I guess it is a GNAT extension). Just do this > > > > EOL : String := "" & ASCII.CR; > > > > or this > > > > EOL : String(1..1) := (1 => ASCII.CR); > > > > These funny syntaxes are necessary if you want EOL to be a string, since CR is a character. > > > > I think that in your case this would work too > > > > EOL : constant Character := ASCII.CR; Thank you for your help. This is the version that eventually worked for me: EOL : String(1..2) := (1 => Ada.Characters.Latin_1.CR, 2 => Ada.Characters.Latin_1.LF) ;