comp.lang.ada
 help / color / mirror / Atom feed
From: david.c.hoos.sr@ada95.com
To: chuu@club-internet.fr
Subject: Re: 3 questions from a beginner
Date: 1998/12/07
Date: 1998-12-07T00:00:00+00:00	[thread overview]
Message-ID: <74ggmh$bmk$1@nnrp1.dejanews.com> (raw)
In-Reply-To: 74cdt6$ni3$1@front4.grolier.fr

In article <74cdt6$ni3$1@front4.grolier.fr>,
  "Pierre" <chuu@club-internet.fr> wrote:
> Hello,
>
> I want to know 3 things :
>
> 1) how we use the composants from the type RECORD in I-O. Give me an example
> please)
>
Supposing you have the type:
type My_Type is
  record
     Name : String (1 .. 30);
     Name_Last : Natural;
     Address : String (1 .. 30;
     Address_Last : Natural;
  end record;

and the object declaration:

My_Object : My_Type;

then you could read these records like this:

Ada.Text_Io.Get_Line
  (Item => My_Object.Name,
   Last => Name_Last);

Ada.Text_Io.Get_Line
  (Item => My_Object.Address,
   Last => Address_Last);

> 2) how we compare 2 strings letter by letter ?
>
To compare the strings A and B, if you only wish to know for sure whether
the two strings are equal, you can simply say if A = B then .....

When you ask "letter by letter" I assume you want to know the firsr letter
which does not match.  To do this, again between strtings named A and B,
you could do this (assuming you have declared the variable
First_Mismatch : Natural;, and that the two strings might not begin with
identical indices):

First_Mismatch := 0;
for C in A'Range loop
  if A (C) /= B (B'First - A'First + C) then
    First_Mismatch := C;
    exit;
  end if;
end loop;

> 3) how we use the function TO_UPPER for only the first letter of a string.
>
I assume you mean the functions To_Upper declared in Ada.Characters.Handling.

You will note that there are two overloaded functions, one for characters and
one for strings.  So, to change the first character of string A to upper case
if it's lower, you could just say:

A (A'First) := Ada.Characters.Handling.To_Upper (A (A'First));

> Thank you in advance
>
> Pierre
>
>

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




  parent reply	other threads:[~1998-12-07  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-06  0:00 3 questions from a beginner Pierre
1998-12-06  0:00 ` Tom Moran
1998-12-06  0:00   ` Pierre
1998-12-07  0:00     ` Matthew Heaney
1998-12-07  0:00 ` david.c.hoos.sr [this message]
1998-12-07  0:00 ` david.c.hoos.sr
replies disabled

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