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 06:47:59 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: dennison@telepath.com (Ted Dennison) Newsgroups: comp.lang.ada Subject: Re: How to delete charcters in a string? Date: 31 Jan 2002 06:47:59 -0800 Organization: http://groups.google.com/ Message-ID: <4519e058.0201310647.3637d7a9@posting.google.com> References: NNTP-Posting-Host: 65.115.221.98 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1012488479 29100 127.0.0.1 (31 Jan 2002 14:47:59 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 31 Jan 2002 14:47:59 GMT Xref: archiver1.google.com comp.lang.ada:19420 Date: 2002-01-31T14:47:59+00:00 List-Id: "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. -- T.E.D. Home - mailto:dennison@telepath.com (Yahoo: Ted_Dennison) Homepage - http://www.telepath.com/dennison/Ted/TED.html