comp.lang.ada
 help / color / mirror / Atom feed
From: Larry Hazel <lhhazel@otelco.net>
Subject: Re: How to delete charcters in a string?
Date: Thu, 31 Jan 2002 10:08:04 -0600
Date: 2002-01-31T10:08:04-06:00	[thread overview]
Message-ID: <3C596BE4.D0F1BFCB@otelco.net> (raw)
In-Reply-To: 4519e058.0201310647.3637d7a9@posting.google.com

Ted Dennison wrote:
> 
> "Anthony Wise" <iamwisey_@hotmail.com> wrote in message news:<mailman.1012350362.32618.comp.lang.ada@ada.eu.org>...
> > (im new to ada by the way)
> >
> > well supose there is a character in a string which i do not want to be seen
> > in the output.  i don't want to change it to anouther character but delete
> > it completely.
> 
> I've seen a lot of answers, but I'll throw mine in anyway because I
> think there's a point that needs to be made.
> 
> Ada strings are *very* different from C strings, and it takes a bit of
> getting used to. In C, strings are essentially a sequence of CHARs
> with a null (0) at the end. In Ada, strings are an array of characters
> of an exact range that *you* specify (by default, the entire array).
> The string ends where your array (or slice of the array) ends. In
> practice strings rarely change, so you can set your string to
> perfectly fill the array, which makes Ada strings much easier to deal
> with (and quicker) than their C counterparts. In the rare cases where
> strings do change, you must keep a length index separately, or use one
> of the alternate dynamic string types in Ada.Strings.*.
> 
> If you are using the String type for your strings, realize that these
> strings are "fixed", and are best dealt with that way. That means that
> rather than trying to remove a character, what you generally would
> look to do is create a new string value (separate from the old one)
> with the character removed. There's a routine in Ada.Strings.Fixed to
> help with that, but if you know its index its just as easy to do it
> with something like:
>   My_String (My_String'first .. Char_Index - 1) &
>   My_String (Char_Index + 1 .. My_String'last);
> 
> However, I should say that solutions to this problem should go on the
> back burner until you have dicovered that you are solving the right
> problem in the first place. Perhaps you are, but often newbies are
> not, and there's no ways to tell from your post. Since Ada and C
> strings are so different, the techniques you may have learned for
> dealing with dynamic C strings are liable to be completely
> inappropriate for dealing with fixed Ada strings. So the first
> question we need answered is *why* you want to remove a character from
> the middle of your string.
> 
Good points Ted.  It caused me to wonder.  Since a null character in Ada means
(essentially) "no character here", rather than end of string, could you just
replace the character you want to delete with a null character?

Larry



  reply	other threads:[~2002-01-31 16:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-30  0:25 How to delete charcters in a string? Anthony Wise
2002-01-30  2:44 ` Steve Doiel
2002-01-30  3:22 ` dale
2002-01-30  6:37   ` tmoran
2002-01-30  7:49     ` Dale Stanbrough
2002-01-30 15:04       ` Marin David Condic
2002-01-30 11:21 ` Preben Randhol
2002-01-30 15:15   ` Marin David Condic
2002-01-31 14:47 ` Ted Dennison
2002-01-31 16:08   ` Larry Hazel [this message]
2002-02-01 15:59     ` Ted Dennison
2002-02-01 17:05     ` Darren New
2002-02-01  6:14   ` tmoran
2002-02-01 15:56     ` Stephen Leake
2002-02-01 17:53       ` Pascal Obry
2002-02-18  3:48         ` David Thompson
2002-02-18 19:44           ` Stephen Leake
     [not found] <F207EAsx2Pwf500RR1h00019d09@hotmail.com>
2002-01-30  1:16 ` Eric Merritt
2002-01-30  1:16 ` Eric Merritt
replies disabled

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