comp.lang.ada
 help / color / mirror / Atom feed
* Re: String Manipulation - Help Needed
  1998-04-06  0:00 String Manipulation - Help Needed Howard Davies
  1998-04-05  0:00 ` Corey Ashford
@ 1998-04-05  0:00 ` Matthew Heaney
  1998-04-06  0:00 ` Michael F Brenner
  1998-04-07  0:00 ` Robert Dewar
  3 siblings, 0 replies; 8+ messages in thread
From: Matthew Heaney @ 1998-04-05  0:00 UTC (permalink / raw)



In article <x3g0MCAC5AK1EwY0@roslyn.demon.co.uk>, Howard Davies
<Howard@roslyn.demon.co.uk> wrote:

>Hi,
>I have a sentence stored in a string and I need to remove all spaces and
>punctuation from the string.
>My 600 page Ada book just says that this requies advanced packages that
>are beyond the scope of the book.
>Can someone help me out?

There are packages that come with the language to do what you want.  The
packages are

Ada.Strings.Fixed
Ada.Strings.Bounded
Ada.Strings.Unbounded
Ada.Strings.Maps
Ada.Characters.Handling

The Trim subprograms can remove whitespace from a string.  Maybe you can
make use of the character mapping functions too.




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

* Re: String Manipulation - Help Needed
  1998-04-06  0:00 String Manipulation - Help Needed Howard Davies
@ 1998-04-05  0:00 ` Corey Ashford
  1998-04-05  0:00 ` Matthew Heaney
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Corey Ashford @ 1998-04-05  0:00 UTC (permalink / raw)




Howard Davies wrote in message ...
>Hi,
>I have a sentence stored in a string and I need to remove all spaces and
>punctuation from the string.
>My 600 page Ada book just says that this requies advanced packages that
>are beyond the scope of the book.
>Can someone help me out?
>
>Many thanks,
>--
>Howard Davies           Howard@roslyn.demon.co.uk

The first idea that comes to mind is something like:

function excise_puctuations(s : string) return string is
    count : natural := 0;
begin
    for i in s'range loop
        if not is_punctuation(s(i)) then
            count := count + 1;
        end if;
    end loop;
    declare
        result : string(1..count);
        idx : natural := 1;
    begin
        for i in s'range loop
            if not is_punctuation(s(i)) then
                result(idx) := s(i);
                idx := idx + 1;
            end if;
        end loop;
        return result;
    end;
end excise_punctuation;

the function is_punctuation would look something like:

function is_punctuation(c : character) return boolean is
begin
    return not (c in 'a'..'z') and not (c in 'A'..'Z');
end is_punctuation;

- Corey

(to send me e-mail, remove the word SPAM from my e-mail address)






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

* String Manipulation - Help Needed
@ 1998-04-06  0:00 Howard Davies
  1998-04-05  0:00 ` Corey Ashford
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Howard Davies @ 1998-04-06  0:00 UTC (permalink / raw)



Hi,
I have a sentence stored in a string and I need to remove all spaces and
punctuation from the string.
My 600 page Ada book just says that this requies advanced packages that
are beyond the scope of the book.
Can someone help me out?

Many thanks,
-- 
Howard Davies           Howard@roslyn.demon.co.uk




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

* Re: String Manipulation - Help Needed
  1998-04-06  0:00 String Manipulation - Help Needed Howard Davies
  1998-04-05  0:00 ` Corey Ashford
  1998-04-05  0:00 ` Matthew Heaney
@ 1998-04-06  0:00 ` Michael F Brenner
  1998-04-07  0:00 ` Robert Dewar
  3 siblings, 0 replies; 8+ messages in thread
From: Michael F Brenner @ 1998-04-06  0:00 UTC (permalink / raw)



From: Howard Davies <Howard@roslyn.demon.co.uk>                          \-[1]

Howard Davies reports an Ada error > ... remove all spaces from a string ...
                                   > My 600 page Ada book just says that 
                                   > this requies advanced packages that
                                   > are beyond the scope of the book.       

It could be that you have misread the book, or it could be that the
book actually says this. If the book actually says this, could you
please post the exact sentence, page number, book name, author, and
publisher, so I can request it to be fixed.

Howard > I have a sentence stored in a string and 
       > I need 
       > to remove all spaces and punctuation from the string. 

An Ada string is an array of characters. Once it is allocated with
a given length, it behaves a lot like arrays of characters in
other languages, except that is has a FIRST and LAST column
number which are of type POSITIVE.

So, you can remove the spaces and punctuation with a loop just like
you would in C, Pascal, Java, FORTRAN, awk, perl, SETL, ALGOL,
EPSILON for the BESM-6, BASIC, etc. 

If your real question is that you do not know how to program this loop,
please repost here and say so, and I will show you to to program it.

Mike Brenner





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

* Re: String Manipulation - Help Needed
  1998-04-07  0:00   ` Howard Davies
  1998-04-07  0:00     ` Robert Dewar
@ 1998-04-07  0:00     ` Michael F Brenner
  1 sibling, 0 replies; 8+ messages in thread
From: Michael F Brenner @ 1998-04-07  0:00 UTC (permalink / raw)



    > The task should be easy. I've already written it in C, 
    > Perl, Haskell and Java and it was easy, but not in Ada.

Could you please post those solutions in those languages here,
so we can see what the problem is? I will convert your
solution to Ada and post it as a response!




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

* Re: String Manipulation - Help Needed
  1998-04-07  0:00   ` Howard Davies
@ 1998-04-07  0:00     ` Robert Dewar
  1998-04-07  0:00     ` Michael F Brenner
  1 sibling, 0 replies; 8+ messages in thread
From: Robert Dewar @ 1998-04-07  0:00 UTC (permalink / raw)



<<The task should be easy. I've already written it in C, Perl, Haskell and
Java and it was easy, but not in Ada.
>>

It is perfectly trivial in Ada! If you have written it in C, then the
Ada code will be almost identical!





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

* Re: String Manipulation - Help Needed
  1998-04-06  0:00 String Manipulation - Help Needed Howard Davies
                   ` (2 preceding siblings ...)
  1998-04-06  0:00 ` Michael F Brenner
@ 1998-04-07  0:00 ` Robert Dewar
  1998-04-07  0:00   ` Howard Davies
  3 siblings, 1 reply; 8+ messages in thread
From: Robert Dewar @ 1998-04-07  0:00 UTC (permalink / raw)



Howard says

<<Hi,
I have a sentence stored in a string and I need to remove all spaces and
punctuation from the string.
My 600 page Ada book just says that this requies advanced packages that
are beyond the scope of the book.
Can someone help me out?
>>

It is not credible that any book says any such idiotic thing. A perfectly
trivial little program can do this. In fact it is quite suitable as a
beginning assignment in Ada!





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

* Re: String Manipulation - Help Needed
  1998-04-07  0:00 ` Robert Dewar
@ 1998-04-07  0:00   ` Howard Davies
  1998-04-07  0:00     ` Robert Dewar
  1998-04-07  0:00     ` Michael F Brenner
  0 siblings, 2 replies; 8+ messages in thread
From: Howard Davies @ 1998-04-07  0:00 UTC (permalink / raw)



In article <dewar.891958926@merv>, Robert Dewar <dewar@merv.cs.nyu.edu>
writes
>It is not credible that any book says any such idiotic thing. A perfectly
>trivial little program can do this. In fact it is quite suitable as a
>beginning assignment in Ada!

The book is "Rendezvous with Ada 95", must be one of the worst
instructional books I've ever used. Anything beyond the most elementary
techniques and you are constantly referred to the Ada 95 reference
manual -  an absolute cop out and little help to someone trying to learn
the language.
 
The reference manual doesn't help much either, totallty uninspired
reading.

The task should be easy. I've already written it in C, Perl, Haskell and
Java and it was easy, but not in Ada.


-- 
Howard Davies           Howard@roslyn.demon.co.uk




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

end of thread, other threads:[~1998-04-07  0:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-06  0:00 String Manipulation - Help Needed Howard Davies
1998-04-05  0:00 ` Corey Ashford
1998-04-05  0:00 ` Matthew Heaney
1998-04-06  0:00 ` Michael F Brenner
1998-04-07  0:00 ` Robert Dewar
1998-04-07  0:00   ` Howard Davies
1998-04-07  0:00     ` Robert Dewar
1998-04-07  0:00     ` Michael F Brenner

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