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-Thread: 103376,c31849ae55c4fb65 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.scarlet.biz!news.scarlet.biz.POSTED!not-for-mail NNTP-Posting-Date: Wed, 29 Nov 2006 12:09:44 -0600 From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Strings and errors... (gnat) References: <1164821430.144822.138100@h54g2000cwb.googlegroups.com> <1164823057.036164.238000@h54g2000cwb.googlegroups.com> Date: Wed, 29 Nov 2006 19:10:22 +0100 Message-ID: <87u00ip1ip.fsf@ludovic-brenta.org> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:9qgKYn/YJb8xeCF1LY7uPjzFbxc= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 62.235.243.191 X-Trace: sv3-HuD32Ky2XPn46ukt3ENhDuWFtLp+hPaPFTcGaEx0mJhdHM2qHeMelzzeIxRnli0bQMmMVmjY3Wvr1nC!nyGtJjBmZMGR0xI2VToq//ZRmc1Xar35eCsPFduDf80qcNh3fNqNr4oG5Ejj7kAkDx/xtd4JYig= X-Complaints-To: abuse@scarlet.be X-DMCA-Complaints-To: abuse@scarlet.biz X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news2.google.com comp.lang.ada:7751 Date: 2006-11-29T19:10:22+01:00 List-Id: tr00per writes: > Robert A Duff napisal(a): >> You can't assign a shorter string into a longer one -- the lengths have >> to match. You could do: >> >> tmp: String := buf(13..26); >> >> or >> >> tmp: constant String := buf(13..26); >> >> and it will take the bounds for tmp from buf(13..26). >> >> Or, you could use Unbounded_Strings. >> >> - Bob > > Actual length of the string is dependend on other data, range here is > for example, so these declarations aren't solution for me, but thanks > anyway. Maybe there is a ready-to-use function for splitting the string > by template, so I don't have to reinvent the wheel? > I have input in format String:String:String. I want to get rid of these > colons and get three seperate strings. Robert's advice still holds: 1) the bounds of a String can be dynamic, so you can also say tmp : constant String := buf (A .. B); -- A and B computed from input 2) You can use Ada.Strings.Unbounded. Now for my own advice: 1) Look at Ada.Strings.Fixed.Find_Token. It will help you find the colons. 2) Look at Ada.Strings.Bounded; it is more efficient than Unbounded_Strings, but you have know the maximum length in advance. 3) If you are writing a subprogram that splits a given string into 3 strings of unknown length, you have basically 4 options: a) return 3 access values to dynamically allocated strings b) return 3 unbounded strings c) return 3 bounded strings d) return 3 fixed strings and 3 Last values, like Ada.Text_IO.Get_Line does. But simply returning 3 fixed strings will not work. -- Ludovic Brenta.