From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,decb0c44a2cbd5dc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-31 08:06:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sunqbc.risq.qc.ca!falcon.america.net!eagle.america.net.POSTED!not-for-mail Message-ID: <3C596BE4.D0F1BFCB@otelco.net> From: Larry Hazel X-Mailer: Mozilla 4.78 [en] (Win98; U) X-Accept-Language: en,x-ns11F8K63r3NhQ,x-ns2r2e09OnmPe2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: How to delete charcters in a string? References: <4519e058.0201310647.3637d7a9@posting.google.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Thu, 31 Jan 2002 10:08:04 -0600 NNTP-Posting-Host: 66.0.32.230 X-Trace: eagle.america.net 1012493205 66.0.32.230 (Thu, 31 Jan 2002 11:06:45 EST) NNTP-Posting-Date: Thu, 31 Jan 2002 11:06:45 EST Organization: 24hoursupport.com Xref: archiver1.google.com comp.lang.ada:19424 Date: 2002-01-31T10:08:04-06:00 List-Id: Ted Dennison wrote: > > "Anthony Wise" wrote in message news:... > > (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