comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <mcondic.auntie.spam@acm.org>
Subject: Re: string manipulation
Date: Sun, 8 Dec 2002 09:02:34 -0500
Date: 2002-12-08T14:02:51+00:00	[thread overview]
Message-ID: <asvjeb$qt2$1@slb6.atl.mindspring.net> (raw)
In-Reply-To: ynvI9.27498$Mn4.329910@wagner.videotron.net

It is technically possible, but the question seems to imply a bit of
confusion about the nature of the type String in Ada. String is a data type
that is an array - nothing more or less. Its element type is Character.
Hence, just as you can declare a type like:

type Vector is array (Integer range <>) of Float ;

and then make specific variables with specific numbers of elements:

My_Vector : Vector (1..10) ;
Your_Vector : Vector (20..50) ;

The exact same thing is legal in Ada for the type String. It is important to
understand that the 'Length doesn't have anything to do with the content of
the string - just the number of positions in the array.

The thing is that often programmers from other languages are used to strings
taking on dynamic sizes depending on what is assigned to them In C, it is
done - in a way - by including a null character somewhere in the array of
characters to indicate termination. This can be done in Ada as well, but is
highly unnatural and not recommended. If you are interested in strings with
a more dynamic nature, look at Ada.Strings.Bounded and Ada.Strings.Unbounded
in the ARM. (Also Ada.Strings.Fixed, if you want to deal with the standard
String type.) Both Bounded and Unbounded strings give you better ability to
look at the length of the string as a function of its content.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================

Gep <nodsa@sdfsffds.net> wrote in message
news:ynvI9.27498$Mn4.329910@wagner.videotron.net...
>
> "Gep" <nodsa@sdfsffds.net> wrote in message
> news:BhvI9.27495$Mn4.328936@wagner.videotron.net...
> > Is it possible to declare a string to be exactly 10 characters long and
> > still be a variable? then
> > for example
> >
> > declare V_string as being exactly 10 characters
> >
> >
> > while not valid
> > loop
> > get_line(V_string, V_length);
> >
> > if v_Art_lng = t_Art_article.t_art_proprietaire.v_nas'length then
> >       Skip_Line;
> >       Valid := True;
> > else
> >     valid :=false;
> >     Put("invalid");
> > end if;
> >
> > end loop;
>
>
> oops the code should be as follows
>
>  while not valid
> loop
>  get_line(V_string, V_length);
>
>  if V_length= V_string'length then
>       Skip_Line;
>       Valid := True;
>  else
>      valid :=false;
>      Put("invalid");
>  end if;
> end loop;
>
>
>





  parent reply	other threads:[~2002-12-08 14:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-07 23:14 string manipulation Gep
2002-12-07 23:20 ` Gep
2002-12-08  2:24   ` Jeffrey Carter
2002-12-08 18:34     ` Gep
2002-12-08 14:02   ` Marin David Condic [this message]
2002-12-08  0:07 ` Jacob Sparre Andersen
2002-12-08  0:12 ` James S. Rogers
  -- strict thread matches above, loose matches on Subject: below --
1998-09-22  0:00 String Manipulation SiliconJesus
1998-09-23  0:00 ` David C. Hoos, Sr.
1998-04-08  0:00 Howard Davies
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox