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: a07f3367d7,8466382b0b7e19ff X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Problems with String processing Date: Sat, 23 Oct 2010 23:24:14 +0300 Organization: Tidorum Ltd Message-ID: <8igujeFc2tU1@mid.individual.net> References: <8igu5kF70sU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net ZT3bHTyLS/+NjorCHYqiww+3X9U5B2KQc/WYY3WlVJe+Uk8vqQ Cancel-Lock: sha1:76PY60eZuC8WnlZgnMPSjmT8kFk= User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) In-Reply-To: <8igu5kF70sU1@mid.individual.net> Xref: g2news1.google.com comp.lang.ada:14700 Date: 2010-10-23T23:24:14+03:00 List-Id: George wrote: > Hi All, > > I have some problems with string processing. My program looks like this: > > begin > -- Ada.Command_Line.Argument_Count is "0" if > -- a) Command_Line.Argument_Count is not implemented (Compiler, OS) > -- b) no arguments given > if Ada.Command_Line.Argument_Count > 0 then > for counter in 1..Ada.Command_Line.Argument_Count loop > Arg = Ada.Characters.Handling.To_Upper(Ada.Command_Line.Argument > (counter)); -- this assignment is the problem Firstly, that isn't an assignment, since you wrote "=". You should write ":=" for an assignment. Secondly, as you have now learned, the Ada String type is a fixed-length string. The simplest solution is to declare the Arg variable as a constant String that is given its value (and length) in the declaration itself: declare Arg : constant String := Ada.Characters.Handling.To_Upper ( Ada.Command_Line.Argument (counter)); begin > if Arg = "ADA83" then > Ada83; > elsif Arg = "ADA95" then > Ada95; > elsif Arg = "ADA2005" then > Ada2005; > elsif Arg = "ATTRIBUTES" then > Attributes; > elsif Arg = "ALL" then > Ada83; > Ada95; > Ada2005; > Attributes; > Sources; > Author; > else -- unknown argument > Ada.Text_IO.put_line("Given Argument is unknown!"); > end if; end; > end loop; > > The assignment Arg = Ada.Characters.Handling.To_Upper > (Ada.Command_Line.Argument(counter)); will not work due to a CONSTRAINT > ERROR. The problem is that the command line arguments given are of > different length. Ada expects the string to match exactly the length of > the defined variable "Arg" with 10 characters. > > How could I solve that problem? Another solution is to use Ada.Strings.Unbounded.Unbounded_String, which is the main Ada type for variable-length strings. HTH, -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .