comp.lang.ada
 help / color / mirror / Atom feed
* Strings
@ 2000-05-27  0:00 Karlene
  2000-05-27  0:00 ` Strings MaggieJohn
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Karlene @ 2000-05-27  0:00 UTC (permalink / raw)


How can you validate a string (eg a name of a person) to check that it only
contains characters, not integers?  I have tried exceptions in my program,
but it dosent seem to cover it.






^ permalink raw reply	[flat|nested] 19+ messages in thread
* RE: Strings
@ 2000-12-21 21:09 Beard, Frank
  2000-12-22 14:19 ` Strings Jef Kelmo
  0 siblings, 1 reply; 19+ messages in thread
From: Beard, Frank @ 2000-12-21 21:09 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

Jef,

>    I just want a usable string. How would I change the above code to do
> this? And could someone please point me to a site that gives actual,
> concrete examples of simple string use?

While Ada.Strings.Bounded has some useful features, it goes a little beyond
"simple" strings.

Is what you are really looking for:

Option 1)

with Ada.Text_IO;

procedure My_Strings is

    -- Anonymous string fixed at 9 characters
    a1 : string := "Some Text";

begin
    Ada.Text_IO.Put(a1);
    Ada.Text_IO.New_Line;  -- Ada.Text_Io.Put_Line(a1) ~ Put and New_Line.

end My_Strings;


Or Option 2)

with Ada.Text_IO;

procedure My_Strings is

    -- Anonymous string fixed at 80 characters
    a1 : string (1..80) := "Some Text" & (10 .. 80 => ' ');

begin
    Ada.Text_IO.Put_Line(a1);

end My_Strings;

Or Option 3)

with Ada.Text_IO;

procedure My_Strings is

    -- Subtype of string fixed as 80 characters
    subtype Bounded_80 is string (1..80);

    a1 : Bounded_80 := "Some Text" & (10 .. 80 => ' ');

begin
    Ada.Text_IO.Put_Line(a1);

end My_Strings;

Frank





^ permalink raw reply	[flat|nested] 19+ messages in thread
* Strings
@ 2000-12-21 17:45 Jef Kelmo
  2000-12-21 18:01 ` Strings Jef Kelmo
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Jef Kelmo @ 2000-12-21 17:45 UTC (permalink / raw)


Hello,

    This is not a homework question. In 5 months, I will begin work that
uses Ada and am trying to become familiar with it now. But I am having a
problem with how to use strings; a problem that seems common across a
number of languages, including C++ and Java.

    I entered the following...

----------------------------------------------------------------------------------------------------------

with Ada.Text_IO;
with Ada.Strings.Bounded;

procedure My_Strings is
    type Bounded_80 is new
Ada.Strings.Bounded.Generic_Bounded_Length(80);

    a1 : Bounded_80.Bounded_String := Bounded_80.To_Bounded_String("Some
Text");

begin
    Ada.Text_IO.Put(Bounded_80.To_String(a1));
    Ada.Text_IO.New_Line;

end My_Strings;
----------------------------------------------------------------------------------------------------------

 ...and when I compile, I get the following...

gcc -c my_strings.adb
my_strings.adb:5:47: subtype mark required in this context
my_strings.adb:5:70: incorrect constraint for this kind of type
my_strings.adb:7:10: invalid prefix in selected component "Bounded_80"
my_strings.adb:7:39: invalid prefix in selected component "Bounded_80"
my_strings.adb:12:21: invalid prefix in selected component "Bounded_80"
gnatmake: "my_strings.adb" compilation error


    So my first guess is to change...

    type Bounded_80 is new
Ada.Strings.Bounded.Generic_Bounded_Length(80);

    ...to...

    subtype Bounded_80 is new
Ada.Strings.Bounded.Generic_Bounded_Length(80);

    ...in which case I get...

gcc -c my_strings.adb
my_strings.adb:5:27: "new" ignored (only allowed in type declaration)
gnatmake: "my_strings.adb" compilation error

    ...so I remove the "new" and get...

gcc -c my_strings.adb
my_strings.adb:5:46: subtype mark required in this context
my_strings.adb:5:69: incorrect constraint for this kind of type
my_strings.adb:7:10: invalid prefix in selected component "Bounded_80"
my_strings.adb:7:39: invalid prefix in selected component "Bounded_80"
my_strings.adb:12:21: invalid prefix in selected component "Bounded_80"
gnatmake: "my_strings.adb" compilation error

    Is it obvious by now that I don't know what I am doing? I have a
copy of Ada as a 2d Language and I looked up the Ada Reference on
adapower.com, but everything is too vague and anything I try does not
work.

    I just want a usable string. How would I change the above code to do
this? And could someone please point me to a site that gives actual,
concrete examples of simple string use?

    Thanks.

James





^ permalink raw reply	[flat|nested] 19+ messages in thread
* Strings
@ 1995-01-25 15:08 Ray Toal
  0 siblings, 0 replies; 19+ messages in thread
From: Ray Toal @ 1995-01-25 15:08 UTC (permalink / raw)


I was impressed by Robert Firth's note in response to the claim made
by a previous poster who claimed

  *p++ = *q++

is more readable than

  loop
    P(I_ := Q(I);
    I := I + 1;
    ...

Rober said a real Ada programmer would write

  P := Q;

True! Touche!  Ada is more terse and more readable than C on this one!

To be fair to the C folks, C++ now features a "language-defined"
string class, so one string can be assigned to another with "=":

  s1 = s2;

My concern is with many in the C "culture" who would probably avoid
the use of this class and stick with "char*"s, on account of some
probable (real or imagined) loss of efficiency.  The vastly improved
clarity of program text that deals with complex objects as single
entities (as opposed to constantly fiddling with their internals)
is a strong point of Ada and a reason why Ada programs are more
readable and far less error prone.

At least the C++ "committee" is realizing this.  Perhaps some day
we can look forward to a **real** array class.  But of course, in C++,
if you WANT safe arrays or safe pointers, you can always code them
yourself.

My preference is to have safety by default, as in Ada, and be specific
when I need Unchecked things.

Ray Toal




^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2000-12-23 21:04 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-27  0:00 Strings Karlene
2000-05-27  0:00 ` Strings MaggieJohn
2000-05-28  0:00   ` Strings Robert Dewar
2000-06-03  0:00     ` Strings Robert I. Eachus
2000-05-27  0:00 ` Strings Robert Dewar
2000-05-27  0:00 ` Strings Robert Dewar
2000-05-27  0:00 ` Strings David C. Hoos, Sr.
  -- strict thread matches above, loose matches on Subject: below --
2000-12-21 21:09 Strings Beard, Frank
2000-12-22 14:19 ` Strings Jef Kelmo
2000-12-22 14:49   ` Strings Larry Kilgallen
2000-12-22 16:35   ` Strings Marin David Condic
2000-12-23 21:04   ` Strings Georg Bauhaus
2000-12-21 17:45 Strings Jef Kelmo
2000-12-21 18:01 ` Strings Jef Kelmo
2000-12-21 18:47 ` Strings mark_lundquist
2000-12-21 18:47 ` Strings mark_lundquist
2000-12-21 23:31   ` Strings gdemont
2000-12-21 19:03 ` Strings David C. Hoos, Sr.
1995-01-25 15:08 Strings Ray Toal

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